├── .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 | 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 |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: ComponentFixture2 | lazy works! 3 |
4 | Go deep 5 |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 |