|
Angularjs4.0路由的js跳转 get传值是如何获取的呢?我们可以通过以下三个步骤来完成:
1.引入NavigationExtras
- import { Router ,NavigationExtras,ActivatedRoute} from '@angular/router';
复制代码
2.定义一个goNewsContent方法执行跳转,用NavigationExtras配置传参
- goNewsContent(){
- let navigationExtras: NavigationExtras = {
- queryParams: { 'session_id': '123' },
- fragment: 'anchor'
- };
- this.router.navigate(['/news'],navigationExtras);
- }
复制代码
3.获取get传值
- constructor(private route: ActivatedRoute) {
- console.log(this.route.queryParams);
- }
复制代码
|
|