0
我正在尝试教程Angular2教程,但它似乎并不了解刷新后的路线。 的源代码可以在https://angular.io/resources/live-examples/tutorial/ts/plnkr.htmlAngular2路由如何去基地目录
@Component({
selector: 'my-app',
template: `
<h1>{{title}}</h1>
<a [routerLink]="['Dashboard']">Dashboard</a>
<a [routerLink]="['Heroes']">Heroes</a>
<router-outlet></router-outlet>
`,
styleUrls: ['app/app.component.css'],
directives: [ROUTER_DIRECTIVES],
providers: [HeroService]
})
@RouteConfig([
{path: '/dashboard', name: 'Dashboard', component: DashboardComponent, useAsDefault: true},
{path: '/heroes', name: 'Heroes', component: HeroesComponent},
{path: '/detail/:id', name: 'HeroDetail', component: HeroDetailComponent}
])
它所做的是,它通过/dashboard
取代基/
但是当你刷新页面,我希望它明白地发现/dashboard
=== /dashboard
而不是/
,因为它认为它是基本目录,所以链接显示/dashboard/dashboard
,并且ts无法加载,因为它们是以相对方式包含的。
由于应对HTML5 pushState的
或更改
PathLocationStrategy
位置的策略HashLocationStrategy
@GünterZöchbauer。我还没有解决我的问题,但它与Angular没有关系,但是Go,所以我会重新说明我的问题。 – Shadowbob您的服务器需要将所有请求重定向到index.html,同样在这里解释http://stackoverflow.com/questions/31415052/angular-2-0-router-not-working-on-reloading-the-browser –