填寫這份《一分鐘調查》,幫我們(開發組)做得更好!去填寫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.