Reputation: 2014
I have two components in a module with their own route. However, only the first one works when testing the routes. Below is how I configure them.
foo-routing.module.ts
const routes: Routes = [
{
path: '',
redirectTo: 'first',
pathMatch: 'full'
},
{
path: 'first',
component: FirstComponent,
},
{
path: 'second',
component: SecondComponent
}
];
app-routing.module.ts
const routes: Routes = [
{
path: 'foo',
loadChildren: () =>
import('src/app/foo/foo.module').then(m => m.FooModule)
},
{
path: APP_ROUTES.DASHBOARD,
loadChildren: () => import('src/app/dashboard/dashboard.module').then(m => m.DashboardModule)
}
// Fallback when no prior route is matched
{ path: '**', redirectTo: '/dashboard' }
];
What am I doing wrong here? When I navigate to foo/first
works okay but when I try foo/second
it only redirect back to foo/first
.
I also try changing the path to something like the below.
const routes: Routes = [
{
path: '',
redirectTo: 'foo/first',
pathMatch: 'full'
},
{
path: 'foo/first',
component: FirstComponent,
},
{
path: 'foo/second',
component: SecondComponent
}
];
This does not also work.
Upvotes: 0
Views: 447
Reputation: 519
// In FooRoutingModule
const routes = [{
path: '',
redirectTo: '/first',
pathMatch: 'full',
children: [
{
path: 'first',
component: FirstComponent
},
{
path: 'second',
component: SecondComponent
}]
}];
Upvotes: 1