html - 角度参数化的默认路由
问题描述
如何使用参数设置默认路由(例如: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: '' },
];
我的项目有一个工作流程,其中用户通过其他网站或带有查询字符串数据的应用程序重定向到我的角度应用程序。是否可以使用带参数的默认路由。
解决方案
是的,有可能只是改变你的路线
const routes: Routes = [
{ path: '', redirectTo: 'landing-page', pathMatch: 'full' },
{ path: "landing-page, component: LandingPageComponent ,
children:[
{ path:':id',component: LandingPageComponent} ]
},
{ path: '**', redirectTo: '' },
];
在你的组件中导入 ActivateRoute 和 Router 模块,并在构造函数中注入它们
contructor(private route: ActivatedRoute, private router: Router){ ... }
将 ActivateRoute 订阅到 ngOnInit
ngOnInit() {
this.route.queryParams.subscribe(params => {
console.log(params);
})
}
推荐阅读
- laravel - Laravel6中具有多个表关系的搜索结果
- python - 在 Pandas 中,获取 groupby 的大小并将值存储在每一行的新列中
- r - 从数据集中创建 ggplot 函数时出错
- php - 如何解决 Yii PHP 中的 GuzzleHttp redeclare 错误?
- vue.js - JHIpster 前端如何进行表单验证?
- javascript - 如何从动态创建的文本字段中收集值?
- html - 如何在暗模式下将链接更改为白色
- html - 当其他标签打开或在标签外进行点击时如何关闭详细信息标签
- python - 一键获取多个结果(python/tkiner)
- python - 将列表中的字符串项转换为浮点数