I am trying to create a parent-child router using this folder structure approach. First of all, I want to be clear if this folder structure of having components inside modules is fine or should I change anything.
If this looks fine I am having trouble creating nested router which I need to fi. Issue explained below with not working and working example below?
Folder Structure
│ app.component.css
│ app.component.html
│ app.component.ts
│ app.module.ts
│ app.routing.ts
│
├───login
│ login.component.css
│ login.component.html
│ login.component.spec.ts
│ login.component.ts
│
└───user //This is a module
│ user.module.ts
│ user.routing.ts
│
├───create-user //This is a component
│ create-user.component.css
│ create-user.component.html
│ create-user.component.spec.ts
│ create-user.component.ts
│
├───list-user //This is a component
│ list-user.component.css
│ list-user.component.html
│ list-user.component.spec.ts
│ list-user.component.ts
│
└───view-user //This is a component
view-user.component.css
view-user.component.html
view-user.component.spec.ts
view-user.component.ts
My app.routing has this
import { Routes } from '@angular/router';
import { FullComponent } from './layouts/full/full.component';
import { LoginComponent } from './login/login.component'
export const AppRoutes: Routes = [
{ path:'login', component: LoginComponent },
{
path: 'admin',
component: FullComponent,
children: [
{
path: 'user',
loadChildren: './user/user.module#UserModule'
}
]
}
];
My user.router contains this
import { Routes } from '@angular/router';
import { CreateComponent } from './create/create.component';
import { ViewComponent } from './view/view.component';
import { ListComponent } from './list/list.component';
export const UserRoutes: Routes = [
{
path: 'create',
component: CreateComponent
},
{
path: 'view',
component: ViewComponent
},
{
path: 'list',
component: ListComponent
}
];
Now when I try to accessing the URL http://localhost:4400/login it works perfectly fine
But when I try the same with http://localhost:4400/admin/user/create my route does not work. I need some help with this.
The following approach is working for me fine I want to follow something like above.
Current Procedure.
app.routing
import { Routes } from '@angular/router';
import { FullComponent } from './layouts/full/full.component';
import { LoginComponent } from './login/login.component'
export const AppRoutes: Routes = [
{ path:'login', component: LoginComponent },
{
path: '',
component: FullComponent,
children: [
{
path: '',
loadChildren: './user/user.module#UserModule'
}
]
}
];
user.routing
import { Routes } from '@angular/router';
import { CreateComponent } from './create/create.component';
import { ViewComponent } from './view/view.component';
import { ListComponent } from './list/list.component';
export const UserRoutes: Routes = [
{
path: 'create-user',
component: CreateComponent
},
{
path: 'view-user',
component: ViewComponent
},
{
path: 'list-user',
component: ListComponent
}
];
The following url works fine http://localhost:4400/login http://localhost:4400/create-user
usersbut your route hasuserplease check