## NavigationExtras
表示在导航过程中使用的额外选项。
### 接口定义
```typescript
interface NavigationExtras {
relativeTo : ActivatedRoute
queryParams : Params
fragment : string
preserveQueryParams : boolean
preserveFragment : boolean
skipLocationChange : boolean
replaceUrl : boolean
}
```
### 属性
- relativeTo : `ActivatedRoute` 在当前路由开启相对路径导航
配置:
```typescript
[{
path: 'parent',
component: ParentComponent,
children: [
{
path: 'list',
component: ListComponent
},
{
path: 'child',
component: ChildComponent
}
]
}]
```
从child路由导航到list路由
```typescript
@Component({...})
class ChildComponent {
constructor(private router: Router, private route: ActivatedRoute) {}
go() {
this.router.navigate(['../list'], { relativeTo: this.route });
}
}
```
- queryParams : `Params`设置URL的查询参数
```typescript
// Navigate to /results?page=1
this.router.navigate(['/results'], { queryParams: { page: 1 } });
```
fragment : `string` 设置URL的has片段
```typescript
// Navigate to /results#top
this.router.navigate(['/results'], { fragment: 'top' });
```
- preserveQueryParams : `boolean` 将查询参数带到下一个导航
```typescript
// Preserve query params from /results?page=1 to /view?page=1
this.router.navigate(['/view'], { preserveQueryParams: true });
```
- preserveFragment : `boolean` 将片段带到下一个导航
```typescript
// Preserve fragment from /results#top to /view#top
this.router.navigate(['/view'], { preserveFragment: true });
```
- skipLocationChange : `boolean` 导航时不向history中添加记录
```typescript
// Navigate silently to /view
this.router.navigate(['/view'], { skipLocationChange: true });
```
replaceUrl : `boolean` 替换当前状态在history中的记录值
```typescript
// Navigate to /view
this.router.navigate(['/view'], { replaceUrl: true });
```
- 说明
- angular 1.x
- ngModelController
- ngOptions
- ngModelOptions
- lifecycle
- directive
- angular 2
- @angular/forms
- 类
- AbstractControl
- AbstractControlDirective
- AbstractFormGroupDirective
- FormControl
- FormArray
- FormBuilder
- FormGroup
- NgControl
- 接口
- controlValueAccessor
- 指令
- DefaultValueAccessor
- Angular 2 生命周期
- OnInit
- DoCheck
- @angular/router
- 配置
- Routes
- 指令
- RouterOutlet
- RouterLink
- 接口
- ActivatedRoute
- UrlTree
- NavigationExtras
- ActivatedRouteSnapshot
- RouterStateSnapshot
- 类
- UrlSegment
- UrlSegmentGroup
- UrlSerializer
- DefaultUrlSerializer
- Router
- bug记得
- @angular/http
- 类
- Http
- Body
- Response
- ResponseOptions
- Header
- Request
- RequestOptions
- URLSearchParams
- @angular/core
- decorator
- Component-decorator
- animation
- DI
- linker
- TemplateRef
- ElementRef
- EmbeddedViewRef
- ViewRef
- ViewContainerRef
- Query
- ComponentFactory
- ComponentRef
- Renderer
- change_detection
- KeyValueDiffers
- IterableDiffers
- ChangeDetectorRef
- ChangeDetectionStrategy
- Zone
- ngZone
- @angular/common
- 指令
- NgTemplateOutlet
- QueryList
- bootstrap4
- card
- form
- 重点关注博客
- 学习过的文章
- 笔记
- Angular 2 双向绑定
- 将字符串解析成DOM
- rx相关
- operators
- combineLatest
- combineAll
- concat(All, Map, *MapTo)
- 背压(backpressure)
- js事件keycode对应表
- 装饰器
- 有用的代码摘录
- 日期操作
- 数量操作
- 字符操作
- rxjs问题
- 小示例
- h5面试准备
- react
- 开发遇到的问题