Created
August 10, 2019 09:54
-
-
Save nathan-lapinski/348b7ec77cc8cd30fd09d015306ae9cd to your computer and use it in GitHub Desktop.
Simple App with Routing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { NgModule } from '@angular/core'; | |
import { BrowserModule } from '@angular/platform-browser'; | |
import { RouterModule } from '@angular/router'; | |
import { Component, Input } from '@angular/core'; | |
/** | |
* Normally, this would be split over multiple files. | |
* Everything is placed into one file here to make it | |
* easier to read. | |
*/ | |
@Component({ | |
template: `<h1>This is Component A</h1>` | |
}) | |
export class ComponentA { | |
} | |
@Component({ | |
template: `<h1>This is Component B</h1>` | |
}) | |
export class ComponentB { | |
} | |
@Component({ | |
selector: 'my-app', | |
template: ` | |
<div> | |
<nav> | |
<h1>Navigation</h1> | |
<a routerLink='/pathA'>Path A</a> | |
| |
<a routerLink='/pathB'>Path B</a> | |
</nav> | |
<router-outlet></router-outlet> | |
</div> | |
` | |
}) | |
export class AppComponent { | |
} | |
const ROUTES = [ | |
{ path: 'pathA', component: ComponentA }, | |
{ path: 'pathB', component: ComponentB }, | |
]; | |
@NgModule({ | |
imports: [ BrowserModule, RouterModule.forRoot(ROUTES) ], | |
declarations: [ AppComponent, ComponentA, ComponentB ], | |
bootstrap: [ AppComponent ] | |
}) | |
export class AppModule { } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment