我开始开发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 });
当我加载我的应用程序时,url显示为:
http://localhost:4200/#/parent/upload
但是,有没有办法让我的路线:
http://localhost:4200/parent/#/upload
我在查官方文件angular-routing,但无法找到任何方法来实现这一点。
任何有用的建议,以实现这一点,将不胜感激!
谢谢!
发布于 2017-10-11 12:12:06
@ChristianBenseler的评论帮助我找到了这个解决方案:
在我的Index.html
文件中,我将基本href更改为:
to
在我的路由模块中,它被更改为:
[
{ path: '', redirectTo: 'upload', pathMatch: 'full' },
{ path: 'upload', component: UploaderComponent },
{path: 'dashboard', component: DashboardComponent},
]
这有助于实现路由为:
http://localhost:4200/parent#/upload
https://stackoverflow.com/questions/46226508
复制相似问题