angular4学习记录 -- 路由
发布时间:2020-12-17 08:48:57 所属栏目:安全 来源:网络整理
导读:Angular4 路由 路由时传递数据 1.在查询参数中传递数据 /product?id=1name=2 = ActivateRoute.queryParams[id] 2.在路由路径中传递数据 {path:/product/:id} = /product/1 = ActivateRoute.params[id] 3.在路由配置中传递数据 {path:product,component:Produ
Angular4 路由路由时传递数据1.在查询参数中传递数据/product?id=1&name=2 => ActivateRoute.queryParams[id] 2.在路由路径中传递数据{path:/product/:id} => /product/1 => ActivateRoute.params[id] 3.在路由配置中传递数据{path:product,component:ProductComponent,data:[{isProd:true}] => ActivatedRoute.data[0][isProd] 路由事件
子路由语法: const routes: Router = [ { path: 'home',component: HomeComponent },{ path: 'others',component: OthersComponent,children: [ path: '',component: XxxComponent,path: 'yyy',component: YyyComponent ] },] 辅助路由
路由守卫在设置路由守卫时需先做下面两步:
canActivate() { var hasPermission:boolean = Math.random() < 0.5; if(!hasPermission) { console.log("用户无权访问次股票详情") } return hasPermission; }
resolve(route: ActivatedRouteSnapshot,state: RouterStateSnapshot): Observable<any> | Promise<any> | any { let id = route.params["id"]; if(id == 1){ return new Stock(1,"IBM"); }else { this.router.navigate(['/home']); return undefined; } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |