如何使用参数设置默认路由(例如: www.test.com/landing-page?uid=123&mode=front&sid=de8d4)
const routes: Routes = [
{ path: '', redirectTo: 'landing-page', pathMatch: 'full' },
{ path: "landing-page", component: LandingPageComponent },
{ path: '**', redirectTo: '' },
];我的项目有一个工作流程,用户被重定向到我的角度应用程序通过其他网站或应用程序与查询字符串中的数据。是否可以使用带参数的默认路由。
发布于 2020-01-27 19:58:07
您只需在路径中添加:加上您的参数:
{ path: "landing-page/:uid/:mode/:sid", component: LandingPageComponent }, 发布于 2020-01-27 20:02:31
好的,只要改变一下路线就可以了。
const routes: Routes = [
{ path: '', redirectTo: 'landing-page', pathMatch: 'full' },
{ path: "landing-page, component: LandingPageComponent ,
children:[
{ path:':id',component: LandingPageComponent} ]
},
{ path: '**', redirectTo: '' },
];在组件中导入ActivateRoute和路由器模块,并将它们注入到构造函数中
contructor(private route: ActivatedRoute, private router: Router){ ... }为ngOnInit订阅ActivateRoute
ngOnInit() {
this.route.queryParams.subscribe(params => {
console.log(params);
})
}https://stackoverflow.com/questions/59930638
复制相似问题