Angular 4 将我的旧哈希 URL 重定向到没有哈希 URL 的新哈希 URL 不起作用



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

示例:http://tvsntorq.com/#Price、http://tvsntorq.com/#Colour

但是现在我已经在 Angular 4 中实现了这个,现在我们有没有哈希的 url。看起来像这样:http://tvsntorq.com/price,http://tvsntorq.com/colour

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

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

但这似乎行不通。我想要的只是将我的旧哈希网址重定向到没有哈希对应网址的新网址。可能吗?帮助。

如果你想在URL中使用哈希,你应该在NgModule中将一个参数传递给你的RouterModule.forRouteimports这样的部分:

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

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

最新更新