Angular 4 Lazy Loading with parameters

后端 未结 1 629
太阳男子
太阳男子 2020-12-16 20:28

Hello I am attempting to lazy load a \"detail module\" while also sending parameters via the URL.

Here is my lazy loaded route:

{
    path: \'venue         


        
相关标签:
1条回答
  • 2020-12-16 20:58

    I don't think that this works:

    {
        path: '',
        redirectTo: 'venue/:name/:id',  
        pathMatch: 'full'
    },
    

    It can't match an "empty" path to a path with parameters.

    The syntax for your lazy loaded route is quite a bit more complex than mine. Mine looks like this:

    {
        path: 'movies',
        loadChildren: './movies/movie.module#MovieModule'
    },
    

    Notice that "parent" route ('movies' in this example) is defined here on the lazy loaded route, and NOT repeated in the loaded modules routes.

    For example:

    RouterModule.forChild([
      { path: '', component: MovieListComponent },
      { path: 'search', component: MovieSearchComponent },
      { path: ':id', component: MovieDetailComponent }
    ])
    

    I would think in your case that the loaded module's routes should look something like this:

    export const VenueDetailRoutes: Route[] = [
        {  
           path: ':name/:id', 
           component: VenueDetailComponent,
            data: {
                shouldDetach: true, // Route will be resused. See CustomResuseStrategy.
                title: null
            }
        }    
    ];
    

    (Though you may want to consider leaving off the custom reuse strategy until you have the basic routes working.)

    0 讨论(0)
提交回复
热议问题