【发布时间】:2017-05-07 12:28:40
【问题描述】:
我是角度新手。我创建了一个博客来显示我的个人资料。 在我的网站中,我有几个组件,我的 app.module 有一个路由配置,如下所示:
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,当我单击主页上的链接时,页面已正确加载。但是,当我最初使用不同的 url(例如localhost:8000/testing)访问我的网站时,Angular 路由似乎无法正常工作。
我得到了这个错误,
如何设置路由器,以便这些 url 可以重定向到我的主页?
【问题讨论】:
-
如果不为其编写自己的子类,就不能将
html5Mode与 Python SimpleHttpServer 一起使用,例如。 gist.github.com/RyanBalfanz/ee579e5dec2d843acff1646943d7e96b -
啊!!问题出在 simpleHttpServer 上?谢谢你
-
如果你想显示这样的 url,你应该使用“真实”的 url,以便用户可以收藏和恢复标签;这意味着您需要在您提供网址的每个位置都有实际页面。它可以是一个常见的错误页面,或者您可以使用服务器来提供实际的最终内容,从而提高 SEO。
标签: javascript angularjs single-page-application ngroute