填寫這份《一分鐘調查》,幫我們(開發組)做得更好!去填寫Home

RouterOutlet

一個佔位符,Angular 會根據當前的路由器狀態動態填充它。

Acts as a placeholder that Angular dynamically fills based on the current router state.

檢視"說明"...

參見

NgModule

選擇器

屬性

屬性說明
@Output('activate')
activateEvents: EventEmitter<any>
@Output('deactivate')
deactivateEvents: EventEmitter<any>
isActivated: boolean唯讀
component: Object唯讀
activatedRoute: ActivatedRoute唯讀
activatedRouteData: Data唯讀

範本變數參考手冊

識別符號用途
outlet#myTemplateVar="outlet"

說明

每個出口可以具有唯一的名稱,該 name 由可選的 name 屬性確定。該名稱不能動態設定或更改。如果未設定,則預設值為 “primary”。

Each outlet can have a unique name, determined by the optional name attribute. The name cannot be set or changed dynamically. If not set, default value is "primary".

      
      <router-outlet></router-outlet>
<router-outlet name='left'></router-outlet>
<router-outlet name='right'></router-outlet>
    

命名出口可以是輔助路由的目標。輔助路由的 Route 物件具有一個 outlet 屬性,用於標識目標出口:

Named outlets can be the targets of secondary routes. The Route object for a secondary route has an outlet property to identify the target outlet:

{path: <base-path>, component: <component>, outlet: <target_outlet_name>}

使用命名的出口和輔助路由,你可以在同一 RouterLink 指令中定位多個出口。

Using named outlets and secondary routes, you can target multiple outlets in the same RouterLink directive.

路由器在導航樹中追蹤每個命名出口的單獨分支,並在 URL 中產生該樹的表示形式。輔助路由的 URL 使用以下語法同時指定主要路由和輔助路由:

The router keeps track of separate branches in a navigation tree for each named outlet and generates a representation of that tree in the URL. The URL for a secondary route uses the following syntax to specify both the primary and secondary routes at the same time:

http://base-path/primary-route-path(outlet-name:route-path)

每當新元件實例化之後,路由出口就會發出一個啟用事件;在銷燬時則發出取消啟用的事件。

A router outlet emits an activate event when a new component is instantiated, and a deactivate event when a component is destroyed.

<router-outlet (activate)='onActivate($event)' (deactivate)='onDeactivate($event)'></router-outlet>
      
      <router-outlet
  (activate)='onActivate($event)'
  (deactivate)='onDeactivate($event)'></router-outlet>
    

方法

RouteReuseStrategy 的指示,從子樹中分離開時呼叫

Called when the RouteReuseStrategy instructs to detach the subtree

detach(): ComponentRef<any>
      
      detach(): ComponentRef<any>
    
引數

沒有引數。

返回值

ComponentRef<any>

RouteReuseStrategy 的指示,把以前分離的子樹重新附加回來時呼叫

Called when the RouteReuseStrategy instructs to re-attach a previously detached subtree

attach(ref: ComponentRef<any>, activatedRoute: ActivatedRoute)
      
      attach(ref: ComponentRef<any>, activatedRoute: ActivatedRoute)
    
引數
ref ComponentRef
activatedRoute ActivatedRoute
deactivate(): void
      
      deactivate(): void
    
引數

沒有引數。

返回值

void

activateWith(activatedRoute: ActivatedRoute, resolver: ComponentFactoryResolver)
      
      activateWith(activatedRoute: ActivatedRoute, resolver: ComponentFactoryResolver)
    
引數
activatedRoute ActivatedRoute
resolver ComponentFactoryResolver