2016-08-07 5 views
0

子ルートの内部のAUXルートは、動作させるための設定方法がわかりません。 私の好きなルート・コンポーネントとルート設定ファイルを持っている:のようなルートの設定ファイルでFirstComponentとSecondComponentを持って角度2の新しいルータrc4の子のAUXルートが機能しない

root.routes.ts  
export const rootRoute:RouterConfig=[ 
     ...ChildrenRoute, 
     {path:'',component:ChildrenRootComponent}, 
     {path:'children-root',component:ChildrenRootComponent}, 
     {path:'other',component:OtherComponent'} 
    ]; 

template: 
      '<a routerLink='children-root'>Children root</a> 
      <a routerLink='other'>Other</a> 
      <router-outlet></router-outlet>' 

とChildrenRootComponent:今すぐ子供ルートからのルート

children.routes.ts  
    export const ChildrenRoute:RouterConfig=[ 
     {path:"",redirectTo:'/children-root',pathMatch:'full'}, 
     {path:'children-root',component:ChildrenRootComponent, 
       children:[ 
        {path:'',component:FirstComponent}, 
        {path:'first',component:FirstComponent}, 
        {path:'second',component:SecondComponent,outlet:'aux'} 
       ] 
     } 
    ]; 
template: 
     ' <a routerLink='first'>First</a> 
       <router-outlet></router-outlet> 
      <a routerLink='aux:second'>Second</a> 
       <router-outlet name="aux"></router-outlet>' 

- 、>セカンドはokですルート子ルート - >最初は動作しません表示エラー:

Error: Cannot match any routes: 'children-root/second' 

変更テンプレート:

' <a routerLink='first'>First</a> 
      <router-outlet></router-outlet> 
    <a routerLink='(aux:second)'>Second</a> 
      <router-outlet name="aux"></router-outlet>' 

があまりにも動作しません。エラー:エラーメッセージで、ここで「)」

Error: Cannot match any routes: 'children-root/second)' 

注意を払う、と

localhost:4200/children-root/(aux:second) 

リロードブラウザで次のようにありません「(」 直接設定されたURLとうまくいくので、私は設定推測します多くのことを検索し、間違ったrouterLinkない、何もこのことについて何かを見つける

答えて

0

で読み取ることができ

this.router.navigateByUrl('/children-root/(first//aux:second)'); 

それとも

<a href="/children-root/(first//aux:second)">Second</a> 

を試してみてください。私達はちょうどルータ・アウトレットでSecondComponentをロードするのhrefがSecondComponentに行くことができますが、ブラウザがページ全体をリロードではなく、今後のRC.5

related GitHub issue

1

RC.4はまだAUXルートでrouterLinkをサポートしていません。このような何か試してみてください:。。

+0

にそれが働いて見るであろう。 – PengGang

+0

このhrefはページをリロードしないでください。私のアプリではリースで私はHashLocationStrategyを使用していますが、これに似たURLがページをリロードしません: '' 'Second' '' –

+0

これはまだRC.5での問題です..いつこれが解決するかもしれないのでしょうか –

1

Rc4。 routerLinkはまだ適切にサポートされていません。 navigateByUrlまたは手動の 'a'タグを使用して、目的の結果を得ることができます。 2番目に移動しようとすると、最初のコンポーネントが表示されていると仮定します。そして、ルートURLの形成の説明はそれだけで固定されていthis

+0

どうすればrc1と3.0.0.alpha.xがrouterLinkをサポートするのですか?誰かが使った? – PengGang

+1

3.0.0.beta2はルータにとって最新のものであり、以前のバージョンではサポートが改善されていません。角度パッケージの残りの部分は重要ではない –

関連する問題