angular4 app中的哈希定位策略

时间:2017-09-14 19:02:14

标签: angular angular-router

我开始使用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的官方文档,但无法找到实现此目的的任何方法。

任何有用的建议都将受到赞赏!!

谢谢!

1 个答案:

答案 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},
]