angular 路由可选参数及必选参数

2020-08-24  本文已影响0人  BuzzLightYearcc

1.路由跳转a标签

<a routerLink="['three/ccd3', 'abc',{ c: '123' }]">ccd3</a>

routerLink 第一项为路由, 第二项必选参数(若无可以省略),第三项为可选参数 用{} 包起来;

2.routing.module.ts的配置 /:a ,表示必选参数a

const routes: Routes = [

    { path: 'ccd3/:a', component: Ccd3Component },

];

3.接收参数

constructor( private route: ActivatedRoute) {}

ngOnInit() {

        this.route.paramMap.subscribe(params => {

            console.log(params);

            this.name = params['a'];

        });

 }

上一篇 下一篇

猜你喜欢

热点阅读