zoukankan      html  css  js  c++  java
  • angular6路由参数的传递与获取

    1.访问路由链接:/test/id

    路由配置:

    {path: 'test/:id', component: TestComponent}

    html传参:

    <a href="javascript:void(0);" [routerLink] = "['/test', '121']">...</a>

    ts传参:

    this.router.navigate(['/test', '121']);//router为Router的实例

    取参:

    this.route.snapshot.params['id'] //route为ActivatedRoute的实例

    2.访问路由链接:/test?id='121'

    路由配置:

    {path: 'test', component: TestComponent}

    html传参:

    <a href="javascript:void(0);" [routerLink] = "['/test']" [queryParams]="{id:'121'}">...</a>

    ts传参:

    this.router.navigate(['/test'],{ queryParams: { id: '121' });

    取参:

    this.route.snapshot.queryParams['id']

    3.不通过路由链接

    {
        path: '',
        component: InterviewSetComponent,
        data: {
          title: '标题',
        }
    }
    
    //取参
    
     this.route.snapshot.data.title;

    如果想获取父路由或子路由的参数,可通过this.route.snapshot.parent 或 this.route.snapshot.children去获取(具体的console.log(this.route.snapshot)去查看)

  • 相关阅读:
    django 2.0 path
    Django
    ORM
    Django简介
    web框架
    HTTP协议
    web应用
    索引
    pyMysql模块
    视图、触发器、存储过程、函数
  • 原文地址:https://www.cnblogs.com/myyouzi/p/12066467.html
Copyright © 2011-2022 走看看