幽梦林子 发表于 2017-8-11 12:07:37

Angularjs4.0路由的动态传值

Angularjs4.0路由的动态传值是如何操作的呢?我们可以通过以下两个步骤来完成:


1.配置动态路由

const routes: Routes = [

{path: 'home', component: HomeComponent},
{path: 'news', component: NewsComponent},
{path: 'newscontent/:id', component: NewscontentComponent},
{
    path: '',
    redirectTo: '/home',
    pathMatch: 'full'
}

];


2.获取动态路由的值

import { Router, ActivatedRoute, Params } from '@angular/router';

constructor(private route: ActivatedRoute) {

}
ngOnInit() {

    console.log(this.route.params);
}



页: [1]
查看完整版本: Angularjs4.0路由的动态传值