? 1. a routing jump method: / routing id = '001' mode - queryParams manner
Routing Configuration: {path: 'Details' , Component: bookDetailsComponent }
. A jump instruction:
routerLink: Jump route, in the form of an array, there are two transmission parameters written: 1. [queryParams] = "{ID: item.id}", 2. [routerLink] = "[ '/ Details', ID]" the first routing value in the array, the value of the second parameter to be passed
. B js achieve Jump:
Where Router is an example of this.router
import { Router } from '@angular/router'
this.router.navigate ([ 'user', 1]); root routing jump starting
this.router.navigate ([ 'User',. 1], { the relativeTo : route}); default is the root route, after setting relative to the current routing jump, jump to the sub-route
this.router.navigate ([ 'user', 1], {queryParams: {id: 1}}); parameter transfer route / user / 1 id = 1?
this.router.navigate(['view', 1], { preserveQueryParams: true }); 默认值为false,设为true,保留之前路由中的查询参数/user?id=1 to /view?id=1
this.router.navigate(['user', 1],{ fragment: 'top' }); 路由中锚点跳转 /user/1#top
this.router.navigate(['/view'], { preserveFragment: true }); 默认值为false,设为true,保留之前路由中的锚点/user/1#top to /view#top
this.router.navigate(['/user',1], { skipLocationChange: true }); 默认值为false,设为true路由跳转时浏览器中的url会保持不变,但是传入的参数依然有效
this.router.navigate(['/user',1], { replaceUrl: true }); 未设置时默认为true,设置为false路由不会进行跳转
2. 以 /路由/参数 的方式跳转 -- snapshot方式
路由配置: { path: 'details/:id', component: bookDetailsComponent }
1. 指令跳转传参:
2. js 跳转:
3. 获取参数
a. 快照方式获取参数 snapshot
b. queryParams 方式获取参数