Skip to content

Instantly share code, notes, and snippets.

@yujiokayama
Last active November 10, 2018 07:22
Show Gist options
  • Select an option

  • Save yujiokayama/3167f9a63e5f1c6ea274f6465e707ca9 to your computer and use it in GitHub Desktop.

Select an option

Save yujiokayama/3167f9a63e5f1c6ea274f6465e707ca9 to your computer and use it in GitHub Desktop.
1.routing-moduleを作成
CLI command
ng g module app-routing --flat --module=app
2.AppRoutingModuleを編集
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { RouterModule, Routes } from '@angular/router';
//必要なコンポーネントをインポート
const routes: Routes = [
{ path: '', component: ChatComponent }, //初期表示
{ path: 'users', loadChildren: './users/users.module#UsersModule' },
{ path: '**', component: NotFoundComponent }, //ワイルドカード(該当しないURLの時)
];
@NgModule({
imports: [
CommonModule,
RouterModule.forRoot(routes)
],
exports: [
RouterModule
],
declarations: []
})
export class AppRoutingModule { }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment