ionic5跳转页面并传参的两种方式

方式一

1.路由中添加模型

首先在app-routing.module.ts中找到即将跳转的页面的path,在path后添加参数名格式为 /:参数名1/:参数名2 …

{ path: 'test/:id/:name', loadChildren: './test/test.module#testPageModule' }
2.跳转页面并传递参数
2.1 ts中跳转
import { Router } from '@angular/router';

constructor(private router:Router) {}

//test为页面,后面接参数 ,参数1,参数2,...
this.router.navigate(["test",参数1,参数2]);
2.2 html中跳转
<ion-button expand="block" routerLink="/test/fjalfjaojfoa/jack" routerDirection="forward">
            跳转页面
</ion-button>
3.接收参数
import { ActivatedRoute, Params } from '@angular/router';

  constructor(public activeRoute: ActivatedRoute) {
    this.uuid = this.activeRoute.snapshot.params['id'];
    this.name = this.activeRoute.snapshot.params['name'];
   }

方式二

1.跳转页面并传递参数
import { Router } from '@angular/router';

//参数必须写到queryParams中
this.router.navigate(["test"],{
        queryParams:{
          id: "12313",
          name: '曹操'
        }
    });
2.接收参数
import { ActivatedRoute, Params } from '@angular/router';

  constructor(public activeRoute: ActivatedRoute) {
    this.uuid = this.activeRoute.snapshot.queryParams['id'];
    this.name = this.activeRoute.snapshot.queryParams['name'];
   }
  
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值