I have an issue with Angular routing I have two modules Basic and Dashboard
In the basic module, I can pass city param for not default city (for default city it should work without param, for example, if New York is default city the path will be http://my.domain/new-york and APP should use HomeComponent) but for not default application should use path http://my.domain/los-angeles and use the same component. List of cities I've got from the back-end. Next level of my structure is categories. I've got categories from the back-end too, but if I try to go to the http://my.domain/category I've got HomeComponent instead of SearchComponent. What the correct way to handle that?
I need:
http://my.domain/category -> SearchComponent
http://my.domain/city/category -> SearchComponent
http://my.domain/city -> HomeComponent
http://my.domain/ -> HomeComponent
app route config:
const routes: Routes = [
{
path: 'dashboard',
canActivate: [AuthService],
loadChildren: () => import('./modules/dashboard/dashboard.module').then(mod => mod.DashboardModule)
},
{
path: '',
loadChildren: () => import('./modules/basic/basic.module').then(mod => mod.BasicModule),
runGuardsAndResolvers: 'always'
},
{
path: '**',
redirectTo: '/'
}
];
Basic module routing
const routes: Routes = [
{
path: '',
component: BasicComponent,
children: [
{
path: '',
component: HomeComponent,
data: {
headerDark: true
}
},
{
path: 'search',
component: SearchComponent,
pathMatch: 'full'
},
{
path: ':city',
component: HomeComponent,
data: {
headerDark: true
},
},
{
path: ':category',
component: SearchComponent
},
{
path: ':city/:category',
component: SearchComponent
},
{
path: ':city/search',
component: SearchComponent,
data: {
headerDark: true
}
}
]
}
];
city/:cityroute and acategory/:category route. If you take a look to the url stackoverflow question, it's how it works :questions/:question