前提在把路由跳转路线写好
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);