├── .editorconfig ├── .gitignore ├── .vscode └── settings.json ├── README.md ├── angular-cli.json ├── e2e ├── app.e2e-spec.ts ├── app.po.ts └── tsconfig.json ├── karma.conf.js ├── package.json ├── protractor.conf.js ├── src ├── app │ ├── app-routing.module.ts │ ├── app.component.html │ ├── app.component.scss │ ├── app.component.spec.ts │ ├── app.component.ts │ ├── app.module.ts │ ├── bundled │ │ ├── bundled-routing.module.ts │ │ ├── bundled.component.html │ │ ├── bundled.component.scss │ │ ├── bundled.component.spec.ts │ │ ├── bundled.component.ts │ │ └── bundled.module.ts │ ├── lazy │ │ ├── deep │ │ │ ├── deep-routing.module.ts │ │ │ ├── deep.component.html │ │ │ ├── deep.component.scss │ │ │ ├── deep.component.spec.ts │ │ │ ├── deep.component.ts │ │ │ ├── deep.module.ts │ │ │ └── third-level │ │ │ │ ├── third-level-routing.module.ts │ │ │ │ ├── third-level.component.html │ │ │ │ ├── third-level.component.scss │ │ │ │ ├── third-level.component.spec.ts │ │ │ │ ├── third-level.component.ts │ │ │ │ └── third-level.module.ts │ │ ├── lazy-routing.module.ts │ │ ├── lazy.component.html │ │ ├── lazy.component.scss │ │ ├── lazy.component.spec.ts │ │ ├── lazy.component.ts │ │ └── lazy.module.ts │ ├── shared │ │ └── index.ts │ ├── simple-route │ │ ├── simple-route.component.html │ │ ├── simple-route.component.scss │ │ ├── simple-route.component.spec.ts │ │ └── simple-route.component.ts │ └── two-words │ │ └── two-words.module.ts ├── assets │ ├── .gitkeep │ └── .npmignore ├── environments │ ├── environment.prod.ts │ └── environment.ts ├── favicon.ico ├── index.html ├── main.ts ├── polyfills.ts ├── styles.scss ├── test.ts ├── tsconfig.json └── typings.d.ts ├── tslint.json └── yarn.lock /.editorconfig: -------------------------------------------------------------------------------- 1 | # Editor configuration, see http://editorconfig.org 2 | root = true 3 | 4 | [*] 5 | charset = utf-8 6 | indent_style = space 7 | indent_size = 2 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | 11 | [*.md] 12 | max_line_length = off 13 | trim_trailing_whitespace = false 14 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See http://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # compiled output 4 | /dist 5 | /tmp 6 | 7 | # dependencies 8 | /node_modules 9 | 10 | # IDEs and editors 11 | /.idea 12 | .project 13 | .classpath 14 | .c9/ 15 | *.launch 16 | .settings/ 17 | 18 | # IDE - VSCode 19 | .vscode/* 20 | !.vscode/settings.json 21 | !.vscode/tasks.json 22 | !.vscode/launch.json 23 | !.vscode/extensions.json 24 | 25 | # misc 26 | /.sass-cache 27 | /connect.lock 28 | /coverage/* 29 | /libpeerconnection.log 30 | npm-debug.log 31 | testem.log 32 | /typings 33 | 34 | # e2e 35 | /e2e/*.js 36 | /e2e/*.map 37 | 38 | #System Files 39 | .DS_Store 40 | Thumbs.db 41 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "typescript.tsdk": "./node_modules/typescript/lib" 3 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Angular CLI Routing Example 2 | 3 | The purpose of this project is to show examples of loading routes by including them directly in the bundle, and by loading them lazily as separate bundles. 4 | 5 | The project shows a simple website, showing a `bundled` route loaded in the main bundle, and a `lazy` route loaded in a seperate bundle (lazy loaded). 6 | 7 | Mostly you just need `npm start` for `ng serve`, and `npm start -- --aot` for `ng serve --aot` (AoT compiler). 8 | 9 | ## Standard Angular CLI Docs 10 | 11 | The project was generated with [angular-cli](https://github.com/angular/angular-cli) version 1.0.0-beta.26. 12 | 13 | The commands below have been modified to ensure you are using the locally installed `angular-cli` package. 14 | 15 | ### Development server 16 | Run `npm start` for a dev server. Navigate to `http://localhost:4200/`. The app will automatically reload if you change any of the source files. 17 | 18 | ### Code scaffolding 19 | 20 | Run `npm run ng -- generate component component-name` to generate a new component. You can also use `ng generate directive/pipe/service/class`. 21 | 22 | ### Build 23 | 24 | Run `npm run ng -- build` to build the project. The build artifacts will be stored in the `dist/` directory. Use the `-prod` flag for a production build. 25 | 26 | ### Running unit tests 27 | 28 | Run `npm run ng -- test` to execute the unit tests via [Karma](https://karma-runner.github.io). 29 | 30 | ### Running end-to-end tests 31 | 32 | Run `npm run ng -- e2e` to execute the end-to-end tests via [Protractor](http://www.protractortest.org/). 33 | Before running the tests make sure you are serving the app via `ng serve`. 34 | 35 | ### Deploying to Github Pages 36 | 37 | Run `npm run ng -- github-pages:deploy` to deploy to Github Pages. 38 | 39 | ### Further help 40 | 41 | To get more help on the `angular-cli` use `ng --help` or go check out the [Angular-CLI README](https://github.com/angular/angular-cli/blob/master/README.md). 42 | -------------------------------------------------------------------------------- /angular-cli.json: -------------------------------------------------------------------------------- 1 | { 2 | "project": { 3 | "version": "1.0.0-beta.26", 4 | "name": "routing-angular-cli" 5 | }, 6 | "apps": [ 7 | { 8 | "root": "src", 9 | "outDir": "dist", 10 | "assets": [ 11 | "assets", 12 | "favicon.ico" 13 | ], 14 | "index": "index.html", 15 | "main": "main.ts", 16 | "test": "test.ts", 17 | "tsconfig": "tsconfig.json", 18 | "prefix": "app", 19 | "mobile": false, 20 | "styles": [ 21 | "styles.scss" 22 | ], 23 | "scripts": [], 24 | "environments": { 25 | "source": "environments/environment.ts", 26 | "dev": "environments/environment.ts", 27 | "prod": "environments/environment.prod.ts" 28 | } 29 | } 30 | ], 31 | "e2e": { 32 | "protractor": { 33 | "config": "./protractor.conf.js" 34 | } 35 | }, 36 | "test": { 37 | "karma": { 38 | "config": "./karma.conf.js" 39 | } 40 | }, 41 | "defaults": { 42 | "styleExt": "scss", 43 | "prefixInterfaces": false, 44 | "inline": { 45 | "style": false, 46 | "template": false 47 | }, 48 | "spec": { 49 | "class": false, 50 | "component": true, 51 | "directive": true, 52 | "module": false, 53 | "pipe": true, 54 | "service": true 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /e2e/app.e2e-spec.ts: -------------------------------------------------------------------------------- 1 | import { RoutingAngularCliPage } from './app.po'; 2 | 3 | describe('routing-angular-cli App', function() { 4 | let page: RoutingAngularCliPage; 5 | 6 | beforeEach(() => { 7 | page = new RoutingAngularCliPage(); 8 | }); 9 | 10 | it('should display message saying app works', () => { 11 | page.navigateTo(); 12 | expect(page.getParagraphText()).toEqual('app works!'); 13 | }); 14 | }); 15 | -------------------------------------------------------------------------------- /e2e/app.po.ts: -------------------------------------------------------------------------------- 1 | import { browser, element, by } from 'protractor'; 2 | 3 | export class RoutingAngularCliPage { 4 | navigateTo() { 5 | return browser.get('/'); 6 | } 7 | 8 | getParagraphText() { 9 | return element(by.css('app-root h1')).getText(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /e2e/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": false, 3 | "compilerOptions": { 4 | "declaration": false, 5 | "emitDecoratorMetadata": true, 6 | "experimentalDecorators": true, 7 | "module": "commonjs", 8 | "moduleResolution": "node", 9 | "outDir": "../dist/out-tsc-e2e", 10 | "sourceMap": true, 11 | "target": "es5", 12 | "typeRoots": [ 13 | "../node_modules/@types" 14 | ] 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /karma.conf.js: -------------------------------------------------------------------------------- 1 | // Karma configuration file, see link for more information 2 | // https://karma-runner.github.io/0.13/config/configuration-file.html 3 | 4 | module.exports = function (config) { 5 | config.set({ 6 | basePath: '', 7 | frameworks: ['jasmine', 'angular-cli'], 8 | plugins: [ 9 | require('karma-jasmine'), 10 | require('karma-chrome-launcher'), 11 | require('karma-remap-istanbul'), 12 | require('angular-cli/plugins/karma') 13 | ], 14 | files: [ 15 | { pattern: './src/test.ts', watched: false } 16 | ], 17 | preprocessors: { 18 | './src/test.ts': ['angular-cli'] 19 | }, 20 | mime: { 21 | 'text/x-typescript': ['ts','tsx'] 22 | }, 23 | remapIstanbulReporter: { 24 | reports: { 25 | html: 'coverage', 26 | lcovonly: './coverage/coverage.lcov' 27 | } 28 | }, 29 | angularCli: { 30 | config: './angular-cli.json', 31 | environment: 'dev' 32 | }, 33 | reporters: config.angularCli && config.angularCli.codeCoverage 34 | ? ['progress', 'karma-remap-istanbul'] 35 | : ['progress'], 36 | port: 9876, 37 | colors: true, 38 | logLevel: config.LOG_INFO, 39 | autoWatch: true, 40 | browsers: ['Chrome'], 41 | singleRun: false 42 | }); 43 | }; 44 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "routing-angular-cli", 3 | "version": "0.0.0", 4 | "license": "MIT", 5 | "angular-cli": {}, 6 | "scripts": { 7 | "ng": "ng", 8 | "reset": "ng init --routing --style=scss", 9 | "start": "ng serve", 10 | "lint": "tslint \"src/**/*.ts\" --project src/tsconfig.json --type-check && tslint \"e2e/**/*.ts\" --project e2e/tsconfig.json --type-check", 11 | "test": "ng test", 12 | "pree2e": "webdriver-manager update --standalone false --gecko false", 13 | "e2e": "protractor" 14 | }, 15 | "private": true, 16 | "dependencies": { 17 | "@angular/common": "^2.3.1", 18 | "@angular/compiler": "^2.3.1", 19 | "@angular/core": "^2.3.1", 20 | "@angular/forms": "^2.3.1", 21 | "@angular/http": "^2.3.1", 22 | "@angular/platform-browser": "^2.3.1", 23 | "@angular/platform-browser-dynamic": "^2.3.1", 24 | "@angular/router": "^3.3.1", 25 | "core-js": "^2.4.1", 26 | "rxjs": "^5.0.1", 27 | "ts-helpers": "^1.1.1", 28 | "zone.js": "^0.7.2" 29 | }, 30 | "devDependencies": { 31 | "@angular/compiler-cli": "^2.3.1", 32 | "@types/jasmine": "2.5.38", 33 | "@types/node": "^6.0.42", 34 | "angular-cli": "1.0.0-beta.26", 35 | "codelyzer": "~2.0.0-beta.1", 36 | "dts-dom": "^0.1.12", 37 | "jasmine-core": "2.5.2", 38 | "jasmine-spec-reporter": "2.5.0", 39 | "karma": "1.2.0", 40 | "karma-chrome-launcher": "^2.0.0", 41 | "karma-cli": "^1.0.1", 42 | "karma-jasmine": "^1.0.2", 43 | "karma-remap-istanbul": "^0.2.1", 44 | "protractor": "~4.0.13", 45 | "ts-node": "1.2.1", 46 | "tslint": "^4.3.0", 47 | "typescript": "~2.0.3" 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /protractor.conf.js: -------------------------------------------------------------------------------- 1 | // Protractor configuration file, see link for more information 2 | // https://github.com/angular/protractor/blob/master/lib/config.ts 3 | 4 | /*global jasmine */ 5 | var SpecReporter = require('jasmine-spec-reporter'); 6 | 7 | exports.config = { 8 | allScriptsTimeout: 11000, 9 | specs: [ 10 | './e2e/**/*.e2e-spec.ts' 11 | ], 12 | capabilities: { 13 | 'browserName': 'chrome' 14 | }, 15 | directConnect: true, 16 | baseUrl: 'http://localhost:4200/', 17 | framework: 'jasmine', 18 | jasmineNodeOpts: { 19 | showColors: true, 20 | defaultTimeoutInterval: 30000, 21 | print: function() {} 22 | }, 23 | useAllAngular2AppRoots: true, 24 | beforeLaunch: function() { 25 | require('ts-node').register({ 26 | project: 'e2e' 27 | }); 28 | }, 29 | onPrepare: function() { 30 | jasmine.getEnv().addReporter(new SpecReporter()); 31 | } 32 | }; 33 | -------------------------------------------------------------------------------- /src/app/app-routing.module.ts: -------------------------------------------------------------------------------- 1 | import {NgModule} from '@angular/core'; 2 | import {Routes, RouterModule} from '@angular/router'; 3 | 4 | import {SimpleRouteComponent} from './simple-route/simple-route.component'; 5 | import {BundledModule} from './bundled/bundled.module'; 6 | 7 | export function loadBundledModule() { return BundledModule; } 8 | 9 | export const routes: Routes = [ 10 | { 11 | path: '', 12 | pathMatch: 'full', 13 | component: SimpleRouteComponent 14 | }, 15 | { 16 | path: 'bundled', 17 | loadChildren: loadBundledModule 18 | // Comment loadChildren above and uncomment the line below to get non lazy loading working with AoT 19 | // Do not delete / comment the `loadBundledModule` declaration or the module will be lazy loaded 20 | // loadChildren: './bundled/bundled.module#BundledModule' 21 | }, 22 | { 23 | path: 'lazy', 24 | loadChildren: './lazy/lazy.module#LazyModule' 25 | } 26 | ]; 27 | 28 | @NgModule({ 29 | imports: [RouterModule.forRoot(routes)], 30 | exports: [RouterModule], 31 | providers: [] 32 | }) 33 | export class AppRoutingModule { } 34 | -------------------------------------------------------------------------------- /src/app/app.component.html: -------------------------------------------------------------------------------- 1 |

2 | {{title}} 3 |

4 | Same Module 5 | Another Module 6 | Lazy Module 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/app/app.component.scss: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Meligy/routing-angular-cli/4196c6627ba01adac0d59c05c47e07c7410e0687/src/app/app.component.scss -------------------------------------------------------------------------------- /src/app/app.component.spec.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:no-unused-variable */ 2 | 3 | import { TestBed, async } from '@angular/core/testing'; 4 | import { RouterTestingModule } from '@angular/router/testing'; 5 | import { AppComponent } from './app.component'; 6 | 7 | describe('AppComponent', () => { 8 | beforeEach(() => { 9 | TestBed.configureTestingModule({ 10 | imports: [ 11 | RouterTestingModule 12 | ], 13 | declarations: [ 14 | AppComponent 15 | ], 16 | }); 17 | TestBed.compileComponents(); 18 | }); 19 | 20 | it('should create the app', async(() => { 21 | const fixture = TestBed.createComponent(AppComponent); 22 | const app = fixture.debugElement.componentInstance; 23 | expect(app).toBeTruthy(); 24 | })); 25 | 26 | it(`should have as title 'app works!'`, async(() => { 27 | const fixture = TestBed.createComponent(AppComponent); 28 | const app = fixture.debugElement.componentInstance; 29 | expect(app.title).toEqual('app works!'); 30 | })); 31 | 32 | it('should render title in a h1 tag', async(() => { 33 | const fixture = TestBed.createComponent(AppComponent); 34 | fixture.detectChanges(); 35 | const compiled = fixture.debugElement.nativeElement; 36 | expect(compiled.querySelector('h1').textContent).toContain('app works!'); 37 | })); 38 | }); 39 | -------------------------------------------------------------------------------- /src/app/app.component.ts: -------------------------------------------------------------------------------- 1 | import { Component } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'app-root', 5 | templateUrl: './app.component.html', 6 | styleUrls: ['./app.component.scss'] 7 | }) 8 | export class AppComponent { 9 | title = 'app works!'; 10 | } 11 | -------------------------------------------------------------------------------- /src/app/app.module.ts: -------------------------------------------------------------------------------- 1 | import { BrowserModule } from '@angular/platform-browser'; 2 | import { NgModule } from '@angular/core'; 3 | import { FormsModule } from '@angular/forms'; 4 | import { HttpModule } from '@angular/http'; 5 | import { AppRoutingModule } from './app-routing.module'; 6 | 7 | import { AppComponent } from './app.component'; 8 | import { SimpleRouteComponent } from './simple-route/simple-route.component'; 9 | 10 | 11 | @NgModule({ 12 | declarations: [ 13 | AppComponent, 14 | SimpleRouteComponent 15 | ], 16 | imports: [ 17 | BrowserModule, 18 | FormsModule, 19 | HttpModule, 20 | AppRoutingModule 21 | ], 22 | providers: [], 23 | bootstrap: [AppComponent] 24 | }) 25 | export class AppModule { } 26 | -------------------------------------------------------------------------------- /src/app/bundled/bundled-routing.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { Routes, RouterModule } from '@angular/router'; 3 | import { BundledComponent } from './bundled.component'; 4 | 5 | export const routes: Routes = [ 6 | { 7 | path: '', 8 | component: BundledComponent 9 | } 10 | ]; 11 | 12 | @NgModule({ 13 | imports: [RouterModule.forChild(routes)], 14 | exports: [RouterModule], 15 | providers: [] 16 | }) 17 | export class BundledRoutingModule { } 18 | -------------------------------------------------------------------------------- /src/app/bundled/bundled.component.html: -------------------------------------------------------------------------------- 1 |

2 | bundled works! 3 |

4 | -------------------------------------------------------------------------------- /src/app/bundled/bundled.component.scss: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Meligy/routing-angular-cli/4196c6627ba01adac0d59c05c47e07c7410e0687/src/app/bundled/bundled.component.scss -------------------------------------------------------------------------------- /src/app/bundled/bundled.component.spec.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:no-unused-variable */ 2 | 3 | import { TestBed, async } from '@angular/core/testing'; 4 | import { BundledComponent } from './bundled.component'; 5 | 6 | describe('Component: Bundled', () => { 7 | it('should create an instance', () => { 8 | let component = new BundledComponent(); 9 | expect(component).toBeTruthy(); 10 | }); 11 | }); 12 | -------------------------------------------------------------------------------- /src/app/bundled/bundled.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'app-bundled', 5 | templateUrl: './bundled.component.html', 6 | styleUrls: ['./bundled.component.scss'] 7 | }) 8 | export class BundledComponent implements OnInit { 9 | 10 | constructor() { } 11 | 12 | ngOnInit() { 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /src/app/bundled/bundled.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { CommonModule } from '@angular/common'; 3 | import { BundledRoutingModule } from './bundled-routing.module'; 4 | import { BundledComponent } from './bundled.component'; 5 | 6 | @NgModule({ 7 | imports: [ 8 | CommonModule, 9 | BundledRoutingModule 10 | ], 11 | declarations: [BundledComponent] 12 | }) 13 | export class BundledModule { } 14 | -------------------------------------------------------------------------------- /src/app/lazy/deep/deep-routing.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { Routes, RouterModule } from '@angular/router'; 3 | import { DeepComponent } from './deep.component'; 4 | 5 | export const routes: Routes = [ 6 | { 7 | path: '', 8 | pathMatch: 'full', 9 | component: DeepComponent 10 | }, 11 | { 12 | path: 'third', 13 | loadChildren: './third-level/third-level.module#ThirdLevelModule' 14 | } 15 | ]; 16 | 17 | @NgModule({ 18 | imports: [RouterModule.forChild(routes)], 19 | exports: [RouterModule], 20 | providers: [] 21 | }) 22 | export class DeepRoutingModule { } 23 | -------------------------------------------------------------------------------- /src/app/lazy/deep/deep.component.html: -------------------------------------------------------------------------------- 1 |

2 | deep works! 3 |

4 | Go Third Level 5 | 6 | -------------------------------------------------------------------------------- /src/app/lazy/deep/deep.component.scss: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Meligy/routing-angular-cli/4196c6627ba01adac0d59c05c47e07c7410e0687/src/app/lazy/deep/deep.component.scss -------------------------------------------------------------------------------- /src/app/lazy/deep/deep.component.spec.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:no-unused-variable */ 2 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 3 | import { By } from '@angular/platform-browser'; 4 | import { DebugElement } from '@angular/core'; 5 | 6 | import { DeepComponent } from './deep.component'; 7 | 8 | describe('DeepComponent', () => { 9 | let component: DeepComponent; 10 | let fixture: ComponentFixture; 11 | 12 | beforeEach(async(() => { 13 | TestBed.configureTestingModule({ 14 | declarations: [ DeepComponent ] 15 | }) 16 | .compileComponents(); 17 | })); 18 | 19 | beforeEach(() => { 20 | fixture = TestBed.createComponent(DeepComponent); 21 | component = fixture.componentInstance; 22 | fixture.detectChanges(); 23 | }); 24 | 25 | it('should create', () => { 26 | expect(component).toBeTruthy(); 27 | }); 28 | }); 29 | -------------------------------------------------------------------------------- /src/app/lazy/deep/deep.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'app-deep', 5 | templateUrl: './deep.component.html', 6 | styleUrls: ['./deep.component.scss'] 7 | }) 8 | export class DeepComponent implements OnInit { 9 | 10 | constructor() { } 11 | 12 | ngOnInit() { 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /src/app/lazy/deep/deep.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { CommonModule } from '@angular/common'; 3 | import { DeepRoutingModule } from './deep-routing.module'; 4 | import { DeepComponent } from './deep.component'; 5 | 6 | @NgModule({ 7 | imports: [ 8 | CommonModule, 9 | DeepRoutingModule 10 | ], 11 | declarations: [DeepComponent] 12 | }) 13 | export class DeepModule { } 14 | -------------------------------------------------------------------------------- /src/app/lazy/deep/third-level/third-level-routing.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { Routes, RouterModule } from '@angular/router'; 3 | import { ThirdLevelComponent } from './third-level.component'; 4 | 5 | const routes: Routes = [ 6 | { 7 | path: '', 8 | component: ThirdLevelComponent 9 | } 10 | ]; 11 | 12 | @NgModule({ 13 | imports: [RouterModule.forChild(routes)], 14 | exports: [RouterModule], 15 | providers: [] 16 | }) 17 | export class ThirdLevelRoutingModule { } 18 | -------------------------------------------------------------------------------- /src/app/lazy/deep/third-level/third-level.component.html: -------------------------------------------------------------------------------- 1 |

2 | third-level works! 3 |

4 | -------------------------------------------------------------------------------- /src/app/lazy/deep/third-level/third-level.component.scss: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Meligy/routing-angular-cli/4196c6627ba01adac0d59c05c47e07c7410e0687/src/app/lazy/deep/third-level/third-level.component.scss -------------------------------------------------------------------------------- /src/app/lazy/deep/third-level/third-level.component.spec.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:no-unused-variable */ 2 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 3 | import { By } from '@angular/platform-browser'; 4 | import { DebugElement } from '@angular/core'; 5 | 6 | import { ThirdLevelComponent } from './third-level.component'; 7 | 8 | describe('ThirdLevelComponent', () => { 9 | let component: ThirdLevelComponent; 10 | let fixture: ComponentFixture; 11 | 12 | beforeEach(async(() => { 13 | TestBed.configureTestingModule({ 14 | declarations: [ ThirdLevelComponent ] 15 | }) 16 | .compileComponents(); 17 | })); 18 | 19 | beforeEach(() => { 20 | fixture = TestBed.createComponent(ThirdLevelComponent); 21 | component = fixture.componentInstance; 22 | fixture.detectChanges(); 23 | }); 24 | 25 | it('should create', () => { 26 | expect(component).toBeTruthy(); 27 | }); 28 | }); 29 | -------------------------------------------------------------------------------- /src/app/lazy/deep/third-level/third-level.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'app-third-level', 5 | templateUrl: './third-level.component.html', 6 | styleUrls: ['./third-level.component.scss'] 7 | }) 8 | export class ThirdLevelComponent implements OnInit { 9 | 10 | constructor() { } 11 | 12 | ngOnInit() { 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /src/app/lazy/deep/third-level/third-level.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { CommonModule } from '@angular/common'; 3 | import { ThirdLevelRoutingModule } from './third-level-routing.module'; 4 | import { ThirdLevelComponent } from './third-level.component'; 5 | 6 | @NgModule({ 7 | imports: [ 8 | CommonModule, 9 | ThirdLevelRoutingModule 10 | ], 11 | declarations: [ThirdLevelComponent] 12 | }) 13 | export class ThirdLevelModule { } 14 | -------------------------------------------------------------------------------- /src/app/lazy/lazy-routing.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { Routes, RouterModule } from '@angular/router'; 3 | import { LazyComponent } from './lazy.component'; 4 | 5 | export const routes: Routes = [ 6 | { 7 | path: '', 8 | pathMatch: 'full', 9 | component: LazyComponent 10 | }, 11 | { 12 | path: 'deep', 13 | // Loading by relative path didn't seem to work here 14 | // loadChildren: './deep/deep.module#DeepModule' 15 | loadChildren: 'app/lazy/deep/deep.module#DeepModule' 16 | } 17 | ]; 18 | 19 | @NgModule({ 20 | imports: [RouterModule.forChild(routes)], 21 | exports: [RouterModule], 22 | providers: [] 23 | }) 24 | export class LazyRoutingModule { } 25 | -------------------------------------------------------------------------------- /src/app/lazy/lazy.component.html: -------------------------------------------------------------------------------- 1 |

2 | lazy works! 3 |

4 | Go deep 5 | 6 | -------------------------------------------------------------------------------- /src/app/lazy/lazy.component.scss: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Meligy/routing-angular-cli/4196c6627ba01adac0d59c05c47e07c7410e0687/src/app/lazy/lazy.component.scss -------------------------------------------------------------------------------- /src/app/lazy/lazy.component.spec.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:no-unused-variable */ 2 | 3 | import { TestBed, async } from '@angular/core/testing'; 4 | import { LazyComponent } from './lazy.component'; 5 | 6 | describe('Component: Lazy', () => { 7 | it('should create an instance', () => { 8 | let component = new LazyComponent(); 9 | expect(component).toBeTruthy(); 10 | }); 11 | }); 12 | -------------------------------------------------------------------------------- /src/app/lazy/lazy.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'app-lazy', 5 | templateUrl: './lazy.component.html', 6 | styleUrls: ['./lazy.component.scss'] 7 | }) 8 | export class LazyComponent implements OnInit { 9 | 10 | constructor() { } 11 | 12 | ngOnInit() { 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /src/app/lazy/lazy.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { CommonModule } from '@angular/common'; 3 | import { LazyRoutingModule } from './lazy-routing.module'; 4 | import { LazyComponent } from './lazy.component'; 5 | 6 | @NgModule({ 7 | imports: [ 8 | CommonModule, 9 | LazyRoutingModule 10 | ], 11 | declarations: [LazyComponent] 12 | }) 13 | export class LazyModule { } 14 | -------------------------------------------------------------------------------- /src/app/shared/index.ts: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Meligy/routing-angular-cli/4196c6627ba01adac0d59c05c47e07c7410e0687/src/app/shared/index.ts -------------------------------------------------------------------------------- /src/app/simple-route/simple-route.component.html: -------------------------------------------------------------------------------- 1 |

2 | simple-route works! 3 |

4 | -------------------------------------------------------------------------------- /src/app/simple-route/simple-route.component.scss: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Meligy/routing-angular-cli/4196c6627ba01adac0d59c05c47e07c7410e0687/src/app/simple-route/simple-route.component.scss -------------------------------------------------------------------------------- /src/app/simple-route/simple-route.component.spec.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:no-unused-variable */ 2 | 3 | import { TestBed, async } from '@angular/core/testing'; 4 | import { SimpleRouteComponent } from './simple-route.component'; 5 | 6 | describe('Component: SimpleRoute', () => { 7 | it('should create an instance', () => { 8 | let component = new SimpleRouteComponent(); 9 | expect(component).toBeTruthy(); 10 | }); 11 | }); 12 | -------------------------------------------------------------------------------- /src/app/simple-route/simple-route.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'app-simple-route', 5 | templateUrl: './simple-route.component.html', 6 | styleUrls: ['./simple-route.component.scss'] 7 | }) 8 | export class SimpleRouteComponent implements OnInit { 9 | 10 | constructor() { } 11 | 12 | ngOnInit() { 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /src/app/two-words/two-words.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { CommonModule } from '@angular/common'; 3 | 4 | @NgModule({ 5 | imports: [ 6 | CommonModule 7 | ], 8 | declarations: [] 9 | }) 10 | export class TwoWordsModule { } 11 | -------------------------------------------------------------------------------- /src/assets/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Meligy/routing-angular-cli/4196c6627ba01adac0d59c05c47e07c7410e0687/src/assets/.gitkeep -------------------------------------------------------------------------------- /src/assets/.npmignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Meligy/routing-angular-cli/4196c6627ba01adac0d59c05c47e07c7410e0687/src/assets/.npmignore -------------------------------------------------------------------------------- /src/environments/environment.prod.ts: -------------------------------------------------------------------------------- 1 | export const environment = { 2 | production: true 3 | }; 4 | -------------------------------------------------------------------------------- /src/environments/environment.ts: -------------------------------------------------------------------------------- 1 | // The file contents for the current environment will overwrite these during build. 2 | // The build system defaults to the dev environment which uses `environment.ts`, but if you do 3 | // `ng build --env=prod` then `environment.prod.ts` will be used instead. 4 | // The list of which env maps to which file can be found in `angular-cli.json`. 5 | 6 | export const environment = { 7 | production: false 8 | }; 9 | -------------------------------------------------------------------------------- /src/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Meligy/routing-angular-cli/4196c6627ba01adac0d59c05c47e07c7410e0687/src/favicon.ico -------------------------------------------------------------------------------- /src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | RoutingAngularCli 6 | 7 | 8 | 9 | 10 | 11 | 12 | Loading... 13 | 14 | 15 | -------------------------------------------------------------------------------- /src/main.ts: -------------------------------------------------------------------------------- 1 | import './polyfills.ts'; 2 | 3 | import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; 4 | import { enableProdMode } from '@angular/core'; 5 | import { environment } from './environments/environment'; 6 | import { AppModule } from './app/app.module'; 7 | 8 | if (environment.production) { 9 | enableProdMode(); 10 | } 11 | 12 | platformBrowserDynamic().bootstrapModule(AppModule); 13 | -------------------------------------------------------------------------------- /src/polyfills.ts: -------------------------------------------------------------------------------- 1 | // This file includes polyfills needed by Angular and is loaded before 2 | // the app. You can add your own extra polyfills to this file. 3 | import 'core-js/es6/symbol'; 4 | import 'core-js/es6/object'; 5 | import 'core-js/es6/function'; 6 | import 'core-js/es6/parse-int'; 7 | import 'core-js/es6/parse-float'; 8 | import 'core-js/es6/number'; 9 | import 'core-js/es6/math'; 10 | import 'core-js/es6/string'; 11 | import 'core-js/es6/date'; 12 | import 'core-js/es6/array'; 13 | import 'core-js/es6/regexp'; 14 | import 'core-js/es6/map'; 15 | import 'core-js/es6/set'; 16 | import 'core-js/es6/reflect'; 17 | 18 | import 'core-js/es7/reflect'; 19 | import 'zone.js/dist/zone'; 20 | -------------------------------------------------------------------------------- /src/styles.scss: -------------------------------------------------------------------------------- 1 | /* You can add global styles to this file, and also import other style files */ 2 | -------------------------------------------------------------------------------- /src/test.ts: -------------------------------------------------------------------------------- 1 | // This file is required by karma.conf.js and loads recursively all the .spec and framework files 2 | 3 | import './polyfills.ts'; 4 | 5 | import 'zone.js/dist/long-stack-trace-zone'; 6 | import 'zone.js/dist/proxy.js'; 7 | import 'zone.js/dist/sync-test'; 8 | import 'zone.js/dist/jasmine-patch'; 9 | import 'zone.js/dist/async-test'; 10 | import 'zone.js/dist/fake-async-test'; 11 | import { getTestBed } from '@angular/core/testing'; 12 | import { 13 | BrowserDynamicTestingModule, 14 | platformBrowserDynamicTesting 15 | } from '@angular/platform-browser-dynamic/testing'; 16 | 17 | // Unfortunately there's no typing for the `__karma__` variable. Just declare it as any. 18 | declare var __karma__: any; 19 | declare var require: any; 20 | 21 | // Prevent Karma from running prematurely. 22 | __karma__.loaded = function () {}; 23 | 24 | // First, initialize the Angular testing environment. 25 | getTestBed().initTestEnvironment( 26 | BrowserDynamicTestingModule, 27 | platformBrowserDynamicTesting() 28 | ); 29 | // Then we find all the tests. 30 | const context = require.context('./', true, /\.spec\.ts$/); 31 | // And load the modules. 32 | context.keys().map(context); 33 | // Finally, start Karma to run the tests. 34 | __karma__.start(); 35 | -------------------------------------------------------------------------------- /src/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "baseUrl": "", 4 | "declaration": false, 5 | "emitDecoratorMetadata": true, 6 | "experimentalDecorators": true, 7 | "lib": ["es6", "dom"], 8 | "mapRoot": "./", 9 | "module": "es6", 10 | "moduleResolution": "node", 11 | "outDir": "../dist/out-tsc", 12 | "sourceMap": true, 13 | "target": "es5", 14 | "typeRoots": [ 15 | "../node_modules/@types" 16 | ] 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/typings.d.ts: -------------------------------------------------------------------------------- 1 | // Typings reference file, you can add your own global typings here 2 | // https://www.typescriptlang.org/docs/handbook/writing-declaration-files.html 3 | -------------------------------------------------------------------------------- /tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "rulesDirectory": [ 3 | "node_modules/codelyzer" 4 | ], 5 | "rules": { 6 | "callable-types": true, 7 | "class-name": true, 8 | "comment-format": [ 9 | true, 10 | "check-space" 11 | ], 12 | "curly": true, 13 | "eofline": true, 14 | "forin": true, 15 | "import-blacklist": [true, "rxjs"], 16 | "import-spacing": true, 17 | "indent": [ 18 | true, 19 | "spaces" 20 | ], 21 | "interface-over-type-literal": true, 22 | "label-position": true, 23 | "max-line-length": [ 24 | true, 25 | 140 26 | ], 27 | "member-access": false, 28 | "member-ordering": [ 29 | true, 30 | "static-before-instance", 31 | "variables-before-functions" 32 | ], 33 | "no-arg": true, 34 | "no-bitwise": true, 35 | "no-console": [ 36 | true, 37 | "debug", 38 | "info", 39 | "time", 40 | "timeEnd", 41 | "trace" 42 | ], 43 | "no-construct": true, 44 | "no-debugger": true, 45 | "no-duplicate-variable": true, 46 | "no-empty": false, 47 | "no-empty-interface": true, 48 | "no-eval": true, 49 | "no-inferrable-types": true, 50 | "no-shadowed-variable": true, 51 | "no-string-literal": false, 52 | "no-string-throw": true, 53 | "no-switch-case-fall-through": true, 54 | "no-trailing-whitespace": true, 55 | "no-unused-expression": true, 56 | "no-use-before-declare": true, 57 | "no-var-keyword": true, 58 | "object-literal-sort-keys": false, 59 | "one-line": [ 60 | true, 61 | "check-open-brace", 62 | "check-catch", 63 | "check-else", 64 | "check-whitespace" 65 | ], 66 | "prefer-const": true, 67 | "quotemark": [ 68 | true, 69 | "single" 70 | ], 71 | "radix": true, 72 | "semicolon": [ 73 | "always" 74 | ], 75 | "triple-equals": [ 76 | true, 77 | "allow-null-check" 78 | ], 79 | "typedef-whitespace": [ 80 | true, 81 | { 82 | "call-signature": "nospace", 83 | "index-signature": "nospace", 84 | "parameter": "nospace", 85 | "property-declaration": "nospace", 86 | "variable-declaration": "nospace" 87 | } 88 | ], 89 | "typeof-compare": true, 90 | "unified-signatures": true, 91 | "variable-name": false, 92 | "whitespace": [ 93 | true, 94 | "check-branch", 95 | "check-decl", 96 | "check-operator", 97 | "check-separator", 98 | "check-type" 99 | ], 100 | 101 | "directive-selector": [true, "attribute", "app", "camelCase"], 102 | "component-selector": [true, "element", "app", "kebab-case"], 103 | "use-input-property-decorator": true, 104 | "use-output-property-decorator": true, 105 | "use-host-property-decorator": true, 106 | "no-input-rename": true, 107 | "no-output-rename": true, 108 | "use-life-cycle-interface": true, 109 | "use-pipe-transform-interface": true, 110 | "component-class-suffix": true, 111 | "directive-class-suffix": true, 112 | "no-access-missing-member": true, 113 | "templates-use-public": true, 114 | "invoke-injectable": true 115 | } 116 | } 117 | --------------------------------------------------------------------------------