首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >angular中的参数化默认路由

angular中的参数化默认路由
EN

Stack Overflow用户
提问于 2020-01-27 19:52:40
回答 2查看 483关注 0票数 0

如何使用参数设置默认路由(例如: www.test.com/landing-page?uid=123&mode=front&sid=de8d4)

代码语言:javascript
复制
const routes: Routes = [
  { path: '', redirectTo: 'landing-page', pathMatch: 'full' },

  { path: "landing-page", component: LandingPageComponent },  
  { path: '**', redirectTo: '' },
];

我的项目有一个工作流程,用户被重定向到我的角度应用程序通过其他网站或应用程序与查询字符串中的数据。是否可以使用带参数的默认路由。

EN

回答 2

Stack Overflow用户

发布于 2020-01-27 19:58:07

您只需在路径中添加:加上您的参数:

代码语言:javascript
复制
{ path: "landing-page/:uid/:mode/:sid", component: LandingPageComponent },  
票数 0
EN

Stack Overflow用户

发布于 2020-01-27 20:02:31

好的,只要改变一下路线就可以了。

代码语言:javascript
复制
      const routes: Routes = [
      { path: '', redirectTo: 'landing-page', pathMatch: 'full' },

      { path: "landing-page, component: LandingPageComponent ,
        children:[
                   { path:':id',component: LandingPageComponent} ]
           },  
      { path: '**', redirectTo: '' },
    ];

在组件中导入ActivateRoute和路由器模块,并将它们注入到构造函数中

代码语言:javascript
复制
contructor(private route: ActivatedRoute, private router: Router){ ... }

为ngOnInit订阅ActivateRoute

代码语言:javascript
复制
ngOnInit() {

    this.route.queryParams.subscribe(params => {
      console.log(params);

    })
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59930638

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档