2017-09-28 6 views
0

私はアプリケーションを起動し、ItdeptComponentに移動しますが、HomeComponentにルーティングされていると思いますか?フィーチャモジュールをロードするとき、アンギュラ一致ルートの順序は?

は私はこのようなルートアプリケーションに対して定義されたルートを持っていると言う:

const appRoutes: Routes = [  
    { path: 'home', component: HomeComponent }, 
    { path: 'it', component: ItdeptComponent }, 
    { path: '', component: HomeComponent, pathMatch: 'full' } 
]; 
export const routing: ModuleWithProviders = RouterModule.forRoot(appRoutes); 

そして、機能モジュールで、この

const itappRoutes: Routes = [ 
    { path: 'it', component: ItdeptComponent }, 
    { path: 'itblog', component: ItBlogPostListComponent }, 
    { path: 'editpost', component: EditBlogPostComponent }, 
    { path: 'createpost', component: CreateBlogPostComponent }, 
    { path: '', component: ItdeptComponent, pathMatch: 'full' } 
]; 

export const routing: ModuleWithProviders = RouterModule.forChild(itappRoutes); 

ようないくつかの経路[更新]

root module routes<br/> 
const appRoutes: Routes = [  
    { path: 'home', component: HomeComponent }, 
    { path: 'it', component: ItdeptComponent }, 
    { path: '', redirectTo: '/home', pathMatch: 'full' } 
]; 

フィーチャーモジュールルート:

const itappRoutes: Routes = [ 
    { path: 'it', component: ItdeptComponent }, 
    { path: 'itblog', component: ItBlogPostListComponent }, 
    { path: 'editpost', component: EditBlogPostComponent }, 
    { path: 'createpost', component: CreateBlogPostComponent }, 
    ***{ path: '', redirectTo:'/it', pathMatch: 'full' } ];*** 

***あなただけの構成要素それぞれのモジュールで

{ path: '', redirectTo: '/home', pathMatch: 'full' }, 

{ path: '', redirectTo: '/it', pathMatch: 'full' }, 

を指定する代わりにredirectToを使用する必要があり、最後のルート

答えて

1

を削除します。それが役に立てば幸い。

+0

はい、同じ経路で2つの異なるルートが得られますか?フィーチャモジュールで空のパスを削除すると、正常に動作します。 – bitshift

+0

あなたがフィーチャモジュールにいるとき、あなたはすでに '/ it'にルーティングされているので、デフォルトのパス' ''を指定すると、子として宣言する必要があります。子として宣言し、その子ルートに 'redirectTo'を適用する方法の詳細は、[this](https://angular.io/guide/router#child-route-configuration)を参照してください。 – amal

関連する問題