NavigationExtras

NavigationExtras

Stable Interface

What it does

Represents the extra options used during navigation.

Interface Overview

interface NavigationExtras {
  relativeTo : ActivatedRoute
  queryParams : Params
  fragment : string
  preserveQueryParams : boolean
  queryParamsHandling : QueryParamsHandling
  preserveFragment : boolean
  skipLocationChange : boolean
  replaceUrl : boolean
}

Interface Description

Interface Details

relativeTo : ActivatedRoute

Enables relative navigation from the current ActivatedRoute.

Configuration:

[{
  path: 'parent',
  component: ParentComponent,
  children: [{
    path: 'list',
    component: ListComponent
  },{
    path: 'child',
    component: ChildComponent
  }]
}]

Navigate to list route from child route:

@Component({...})
class ChildComponent {
  constructor(private router: Router, private route: ActivatedRoute) {}

  go() {
    this.router.navigate(['../list'], { relativeTo: this.route });
  }
}
queryParams : Params

Sets query parameters to the URL.

// Navigate to /results?page=1
this.router.navigate(['/results'], { queryParams: { page: 1 } });
fragment : string

Sets the hash fragment for the URL.

// Navigate to /results#top
this.router.navigate(['/results'], { fragment: 'top' });
preserveQueryParams : boolean

Preserves the query parameters for the next navigation.

deprecated, use queryParamsHandling instead

// Preserve query params from /results?page=1 to /view?page=1
this.router.navigate(['/view'], { preserveQueryParams: true });
queryParamsHandling : QueryParamsHandling

config strategy to handle the query parameters for the next navigation.

// from /results?page=1 to /view?page=1&page=2
this.router.navigate(['/view'], { queryParams: { page: 2 },  queryParamsHandling: "merge" });
preserveFragment : boolean

Preserves the fragment for the next navigation

// Preserve fragment from /results#top to /view#top
this.router.navigate(['/view'], { preserveFragment: true });
skipLocationChange : boolean

Navigates without pushing a new state into history.

// Navigate silently to /view
this.router.navigate(['/view'], { skipLocationChange: true });
replaceUrl : boolean

Navigates while replacing the current state in history.

// Navigate to /view
this.router.navigate(['/view'], { replaceUrl: true });

exported from router-index, defined in router/src/router.ts

© 2010–2017 Google, Inc.
Licensed under the Creative Commons Attribution License 4.0.
https://angular.io/docs/ts/latest/api/router/index/NavigationExtras-interface.html

在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号

意见反馈
返回顶部