Skip to content

Instantly share code, notes, and snippets.

@DaveMBush
Last active July 15, 2017 19:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DaveMBush/49d3511d11b1f16a976f9e9796511381 to your computer and use it in GitHub Desktop.
Save DaveMBush/49d3511d11b1f16a976f9e9796511381 to your computer and use it in GitHub Desktop.
Angular Routing
export const routes: Routes = [];
@NgModule({})
export class AppRoutesModule {}
import {RouterModule, Routes} from ‘@anguler/router’;
export const routes: Routes = [];
@NgModule({})
export class AppRoutesModule {}
export const routes: Routes = [{
path: ‘page1’,
children: [
{
path: ‘’,
pathMatch: ‘full’,
component: ‘Page1Component’ },
{
path: ‘subpage’,
component: Page1SubpageComponent
}]}, {
path: ‘page2’,
component: Page2Component
}]
import {Page1Component} from './routes/page1/page1.component';
import {Page2Component} from './routes/page2/page2.component';
import {Page1SubpageComponent}
from './routes/page1.subpage/page1-subpage.component';
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutesModule {
}
{
path: ‘’,
redirectTo: ‘page1’,
pathMatch: ‘full’
},
export const routes: Routes = [{
path: '',
redirectTo: 'page1',
pathMatch: 'full'
}, {
path: 'page1',
loadChildren: './routes/page1/page1.module#Page1Module'
}, {
path: 'page2',
loadChildren: './routes/page2/page2.module#Page2Module'
}]
<router-outlet></router-outlet>
import {AppRoutesModule} from ‘./app-routes.module’;
@NgModule({
…,
imports: [
…,
AppRoutesModule
],
}
RouterModule.forChild([{
path: '',
pathMatch: 'full',
component: Page1SubpageComponent
}]),
RouterModule.forChild([{
path: '',
pathMatch: 'full',
component: Page1Component
}, {
path: 'subpage',
loadChildren: ‘../page1.subpage/page1-subpage.module#Page1SubpageModule’
}]),
RouterModule.forChild([{
path: '',
pathMatch: 'full',
component: Page2Component
}]),
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment