can somebody tell me how correct to set up routing when using multiple modules in my project? I have app.module and courses.module with some components declared in. I want to know how to connect modules and edit properly routing in courses.module, thats share routes: "/courses/list" and "/courses/detail"
app.routing.module.ts
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
//import { CoursesRoutingModule } from './components/courses/courses-routing.module';
const routes: Routes = [
{
path: 'courses',
loadChildren: './components/courses/courses-routing.module#CoursesRoutingModule'
}
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule { }
app.component.html
<h1>App.component</h1>
<p>
<button routerLink="/">HOME</button>
<button routerLink="/courses">KURSY</button>
</p>
<router-outlet></router-outlet>
And here's courses component:
courses.routing.module.ts
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { CoursesComponent } from './courses.component';
import { CoursesDetailComponent } from './components/courses-detail/courses-detail.component';
import { CoursesListComponent } from './components/courses-list/courses-list.component';
const routes: Routes = [
// {
// path: 'courses',
// loadChildren: '/src/app/components/courses/courses.module'
// }
// ,
// {
// path: 'courses/list',
// component: CoursesListComponent,
// outlet: 'courseslist'
// }
];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule]
})
export class CoursesRoutingModule { }
courses.component.html:
<p>
<button routerLink="/">HOME</button>
<button routerLink="/courses/list">list</button>
<button routerLink="/courses/detail">detail</button>
</p>