Skip to content

Instantly share code, notes, and snippets.

@brandonroberts
Last active August 22, 2016 06:48
Show Gist options
  • Save brandonroberts/f17493b416092055615b8fc0830c127a to your computer and use it in GitHub Desktop.
Save brandonroberts/f17493b416092055615b8fc0830c127a to your computer and use it in GitHub Desktop.
Route Modules
@NgModule({
imports: [
routing,
MainModule
]
})
export class MainModule {}
const routes: Routes = [
{path: 'home', component: Home},
{path: 'settings', component: Settings},
{path: '', redirectTo: '/home', pathMatch: 'full'}
]
export const routing = RouterModule.forRoot(routes);
// The router will flatten all the route arrays together
const routes: Routes = [
{path: 'home', component: Home},
{path: 'settings', component: Settings},
{path: '', redirectTo: '/home', pathMatch: 'full'},
{
path: 'apis’,
component: Main,
children: [
{path: ':apiCall', component: ApiDocList},
{path: ':apiCall/detail/:operation', component: ApiDocDetail}
]
}
]
]
@NgModule({
imports: [
mainRouting
]
})
export class MainModule {}
const mainRoutes: Routes = [
{
path: 'apis’,
component: Main,
children: [
{path: ':apiCall', component: ApiDocList},
{path: ':apiCall/detail/:operation', component: ApiDocDetail}
]
}
]
export const mainRouting = RouterModule.forChild(mainRoutes);
@SamVerschueren
Copy link

The flattened-routes-example.ts has some minor issues, probably some copy-pasting errors. It has one []](https://gist.github.com/brandonroberts/f17493b416092055615b8fc0830c127a#file-flattened-routes-example-ts-L16) too much at the end.

const routes: Routes = [
  {path: 'home', component: Home},
  {path: 'settings', component: Settings},
  {path: '', redirectTo: '/home', pathMatch: 'full'},
  {
    path: 'apis',
    component: Main,
    children: [
      {path: ':apiCall', component: ApiDocList},
      {path: ':apiCall/detail/:operation', component: ApiDocDetail}
    ]
  }
]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment