我是新来角。我创建了一个展示我的个人资料的博客。 在我的网站,我有几个分量和我app.module具有路由的配置,如图所示:如何正确使用Angular 1.5进行SPA的路由?
app.config(function($locationProvider, $routeProvider){
$locationProvider.html5Mode({
enabled:true,
requireBase: false
})
$routeProvider.
when("/", {
template: "<research-overview></research-overview>"
}).
when("/research-interests", {
template: "<research-interests></research-interests>"
}).
otherwise({
redirectTo: "/"
})
});
这里是我的组件的例子:
angular.module('researchOverview', [])
.component('researchOverview', {
templateUrl: '/templates/research-overview.html',
});
我试图在本地使用python -m SimpleHttpServer
运行服务器,以便我可以使用浏览器访问我的本地网站localhost:8000
,当我点击我主页上的链接时,该页面已正确加载。但是,当我最初使用不同的网址访问我的网站时(例如localhost:8000/testing
),角度路线似乎无法正常工作。 我得到这个错误,而不是,
如何设置路由器,使这些URL可以被重定向到我的主页?
你不能在Python中使用带'SimpleHttpServer'的'html5Mode',而无需为它编写自己的子类,例如。 https://gist.github.com/RyanBalfanz/ee579e5dec2d843acff1646943d7e96b – Claies
啊!问题在于simpleHttpServer?感谢这 –
如果你想展示这样的网址,你应该使用“真实”的网址,以便用户可以收藏和恢复标签;这意味着你需要在每个地点给出一个url的实际页面。它可能是一个常见的错误页面,或者您可以使用服务器来服务实际的最终内容,从而提高搜索引擎优化。 – dandavis