Skip to content

Instantly share code, notes, and snippets.

@nathan-lapinski
Created August 10, 2019 09:54
Show Gist options
  • Save nathan-lapinski/348b7ec77cc8cd30fd09d015306ae9cd to your computer and use it in GitHub Desktop.
Save nathan-lapinski/348b7ec77cc8cd30fd09d015306ae9cd to your computer and use it in GitHub Desktop.
Simple App with Routing
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>
&nbsp;
<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