|
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);
- }
复制代码
|
|