2017-08-04 4 views
0

J'essaie de comprendre le fonctionnement du routage angulaire 2. J'ai défini deux chemins de l'enfant 'movieCategory/create' et le chemin: 'movieCategory', Quand je tape http://localhost:4200/#/movieCategory cela fonctionne très bien et montre le composant MovieCategory. Mais quand je tape http://localhost:4200/#/movieCategory/create au navigateur, il montre le composant CreateMovieCategory mais l'URL devient http://localhost:4200/#/movieCategory encore. Qu'est-ce que je fais de mal? Et la deuxième question d'où vient le #?Route redirigeant vers l'URL principale

Mes itinéraires

export const routes: Routes = [ 
    { 
    path: '', 
    redirectTo: 'movieCategory', 
    pathMatch: 'full', 
    }, 
    { 
    path: '', 
    component: FullLayoutComponent, 
    data: { 
     title: 'Film Kategorileri' 
    }, 
    children: [ 
     { 
     path: 'movieCategory/create', 
     component: CreateMovieCategory 
     }, 
     { 
     path: 'movieCategory', 
     component: MovieCategory 
     } 

    ] 
    } 
]; 

J'ai également un bouton qui affiche le même comportement quand je clique dessus.

<button class="btn btn-primary pull-right" type="button" [routerLink]="['/movieCategory/create']"> 

Merci à l'avance

Répondre

0
export const routeConfig:Routes = [ 
    { 
     path: '', 
     component: FullLayoutComponent 
    } 

    {   
     path: 'movieCategory', 
     children: [ 
      { 
      path: 'create', 
      component: CreateMovieCategory    
      } 
     ]  
    } 
]; 

Pour plus d'informations vérifier ce LINK.

Si vous utilisez PathLocationStrategy comme décrit here, vous pouvez supprimer le hachage dans l'URL.