【问题标题】:How to pass multiple route parameters in Ionic-Angular?如何在 Ionic-Angular 中传递多个路由参数?
【发布时间】:2020-07-04 15:23:32
【问题描述】:

我可以通过 Ionic 5 中的 page1/id1 之类的路线获取单个参数。 如果我想为一个模块获取多个参数,我该怎么做?

【问题讨论】:

    标签: angular ionic-framework hybrid-mobile-app angular-routerlink


    【解决方案1】:

    app-routing.module.ts中,修改路径到-

    {
    path: 'page1/:id1/:id2',
    loadChildren: () => import('./pages/page1/page1.module').then(m => m.Page1PageModule)
    },
    

    在您要访问此页面的页面中,例如 page0.page.html include-

    <ion-item button [routerLink]="['/', 'page1', id1,id2]" >Go to Page1 </ion-item>
    

    page1.page.ts 中,为了访问这些参数,在 ngOnInit 中包含以下内容 -

    import { ActivatedRoute, Router} from '@angular/router';
    
    ..
    constructor(private route : ActivatedRoute, private router : Router){}
    
    ngOnInit() {
       this.route.paramMap.subscribe(params => {
          let id1 = params.get('id1');
          let id2 = params.get('id2');
       });
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-09-21
      • 2019-03-17
      • 1970-01-01
      • 2015-10-14
      • 1970-01-01
      • 1970-01-01
      • 2019-08-30
      • 2014-06-08
      相关资源
      最近更新 更多