【问题标题】:Angular 4 redirect for my old hash URLs to new without hash URLs is not working我的旧哈希 URL 的 Angular 4 重定向到没有哈希 URL 的新 URL 不起作用
【发布时间】:2018-09-14 22:03:34
【问题描述】:

我们有一个单页应用程序,它以前是简单的选项卡结构,所有的选项卡点击都有各自的#url。

示例:http://tvsntorq.com/#Pricehttp://tvsntorq.com/#Colour

但现在我已经在 Angular 4 中实现了这一点,现在我们有了没有哈希的 url。如下所示:http://tvsntorq.com/pricehttp://tvsntorq.com/colour

现在我在路由器模块中添加了以下路由:

...
  {
    path: '#Colour',
    redirectTo: 'colour',
    pathMatch: 'full'
  },
  {
    path: '#Price',
    redirectTo: 'price',
    pathMatch: 'full'
  },  
 {
    path: 'colour',
    component: ColorComponent
  },
  {
    path: 'price',
    component: PriceComponent
  }
....

但这似乎不起作用。我想要的只是将我的旧的带有哈希 url 重定向到新的没有哈希对应的 url。可能吗?帮助。

【问题讨论】:

    标签: angular url-redirection angular-routing angular4-router


    【解决方案1】:

    如果您想在 URL 中使用哈希,您应该在 NgModuleimports 部分向您的 RouterModule.forRoute 传递一个参数,如下所示:

    RouterModule.forRoute(yourRoutesArray, {useHash: true})
    

    如果您不需要它,只需省略第二个参数或发送 false 代替。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-28
      • 2013-04-04
      • 1970-01-01
      • 1970-01-01
      • 2014-08-14
      • 1970-01-01
      相关资源
      最近更新 更多