填写这份《一分钟调查》,帮我们(开发组)做得更好!去填写Home

NavigationBehaviorOptions

修改 Router 导航策略的选项。为 Router 导航功能提供包含任何这些属性的对象,以控制导航的处理方式。

Options that modify the Router navigation strategy. Supply an object containing any of these properties to a Router navigation function to control how the navigation should be handled.

      
      interface NavigationBehaviorOptions {
  skipLocationChange?: boolean
  replaceUrl?: boolean
  state?: {...}
}
    

参见

属性

属性说明
skipLocationChange?: boolean

导航时不要把新状态记入历史

When true, navigates without pushing a new state into history.

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

导航时不要把当前状态记入历史

When true, navigates while replacing the current state in history.

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

由开发人员定义的状态,可以传递给任何导航。当执行导航时会通过由 Router.getCurrentNavigation() 方法返回的 Navigation.extras 对象来访问此值。

Developer-defined state that can be passed to any navigation. Access this value through the Navigation.extras object returned from the Router.getCurrentNavigation() method while a navigation is executing.

导航完成后,路由器会将包含该值和 navigationId 的对象写入 history.state。在激活此路由之前,会在调用 location.go()location.replaceState() 时写入该值。

After a navigation completes, the router writes an object containing this value together with a navigationId to history.state. The value is written when location.go() or location.replaceState() is called before activating this route.

需要注意的是 history.state 不应该用于对象相等测试,因为每次导航时路由器都会添加 navigationId

Note that history.state does not pass an object equality test because the router adds the navigationId on each navigation.