我开始使用angular4应用,我在该应用中使用hash location strategy
。我能够介绍hash location strategy
并完全正常工作。
我的问题是:有什么办法可以调整网址中hash
的位置吗?
例如:我的路由模块是:
[
{path: '', redirectTo: 'parent', pathMatch: 'full'},
{ path: 'parent',
children: [
{ path: '', redirectTo: 'upload', pathMatch: 'full' },
{ path: 'upload', component: UploaderComponent },
{path: 'dashboard', component: DashboardComponent},
]
}
]
我正在注册这些路线:
RouterModule.forRoot(routes, { useHash: true });
当我加载我的应用时,网址会显示为:
http://localhost:4200/#/parent/upload
但是,有没有办法让我的路线成为:
http://localhost:4200/parent/#/upload
我正在查看angular-routing的官方文档,但无法找到实现此目的的任何方法。
任何有用的建议都将受到赞赏!!
谢谢!
答案 0 :(得分:0)
@ ChristianBenseler的评论帮助我找到了这个解决方案:
在我的setState
文件中,我将基本href更改为:
Index.html
在我的路由模块中,它被更改为:
<base href="/"> to <base href="/parent">
这有助于实现路线:
[
{ path: '', redirectTo: 'upload', pathMatch: 'full' },
{ path: 'upload', component: UploaderComponent },
{path: 'dashboard', component: DashboardComponent},
]