angular页面跳转时,用get传值和动态路由跳转传值

本文介绍了在Angular中如何进行页面跳转时传递值的方法,包括使用GET方式通过URL参数传递值以及通过动态路由配置进行跳转传值的详细步骤。在GET方式中,值被附加到链接后作为查询参数;而在动态路由跳转中,值在配置路由和调用导航时传递。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

前提在把路由跳转路线写好

const routes: Routes = [
  {
    path: 'bottom',component:BottomMuduleComponent
  },
  {
    path: 'header',component:HeaderModuleComponent
  },
  {
    path: 'main',component:MainMoudleComponent
  },
  {
    path: 'slidebar',component:SlidebarModuleComponent 
  },
  {
    path: 'news',component:NewsComponent 
  },
  {
    path: 'newscontent',component:NewscontentComponent
  },
  {
    //默认路由,放置在最后
    path: '**',component:SlidebarModuleComponent 
  },

];

//get 传值
// 1 跳转(在跳转页面将值传入到跳转后的页面)

// <ol>
//   <li *ngFor="let item of list;let key=index">
//     <!-- <a>{{key}}--------- {{item}}</a> -->
//     <a [routerLink]="['/newscontent']" [queryParams]="{adi:key}">{{key}} ----{{item}}</a>
//   </li>
// </ol>

注:queryParams可以在get链接后面带入参数,他是一个对象
http://localhost:8000/newscontent?adi=9

// 2 接收(在跳转之后的页面接收跳转之前的页面

// import { ActivatedRoute } from '@angular/router')

// constructor(public route:ActivatedRoute) { }

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

angular 动态路由跳转传值
//1 配置路由

// {
//   path: 'newscontent/:aid',component:NewscontentComponent
// }
//

2 传值

// <ul>
//   <li *ngFor="let item of list, let key=index">
//     <a [routerLink]="['/newscontent/', key]"
//     routerLinkActive="router-link-active">{{item}} ----- {{key}}</a>
//   </li>
// </ul>

/3 接收

// import { ActivatedRoute } from '@angular/router')

// constructor(public route:ActivatedRoute) { }

// this.route.parmas.subscribe((data)=>{
//   console.log(data);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值