angular 参数用 & 分隔的路由路径
angular route path with parameters separated with &
这种类型的路径不工作:
{ path: 'account/finalize?user=:user&token=:token', component: MyComponent }
当我访问 http://localhost:4200/account/finalize?user=devanshu&token=122323
时出现找不到路由错误
但这是有效的:
{ path: 'account/finalize/:school/:token', component: MyComponent }
所以,我可以访问 http://localhost:4200/account/finalize/devanshu/122323
这里有什么问题?为什么第一种情况会出错?
你可以使用
path: 'account/finalize'
并在导航时将用户和令牌作为查询参数发送
this.router.navigate(['/account/finalize'], { queryParams: { user: 'user', token: 'your token' } });
我认为你不需要传递这些参数:
user=:user&token=:token
您可以在req.body
中获取这些参数
如果有任何特定的组件,则必须将条件放在函数中。
这种类型的路径不工作:
{ path: 'account/finalize?user=:user&token=:token', component: MyComponent }
当我访问 http://localhost:4200/account/finalize?user=devanshu&token=122323
时出现找不到路由错误但这是有效的:
{ path: 'account/finalize/:school/:token', component: MyComponent }
所以,我可以访问 http://localhost:4200/account/finalize/devanshu/122323
这里有什么问题?为什么第一种情况会出错?
你可以使用
path: 'account/finalize'
并在导航时将用户和令牌作为查询参数发送
this.router.navigate(['/account/finalize'], { queryParams: { user: 'user', token: 'your token' } });
我认为你不需要传递这些参数:
user=:user&token=:token
您可以在req.body
如果有任何特定的组件,则必须将条件放在函数中。