Last active
January 5, 2018 09:46
-
-
Save kevinchisholm/9f8c37a4d77dd50cf92a034cc32e2ae1 to your computer and use it in GitHub Desktop.
Angular Routing Basics
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
<nav id="main-nav"> | |
<ul> | |
<li [routerLink]="[ '/home']" class="link">Home</li> | |
<li [routerLink]="[ '/products']" class="link">Products</li> | |
<li [routerLink]="[ '/about']" class="link">About</li> | |
</ul> | |
</nav> | |
<router-outlet></router-outlet> |
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 {platformBrowserDynamic} from '@angular/platform-browser-dynamic'; | |
import {BrowserModule} from '@angular/platform-browser'; | |
import {Http, HttpModule, BaseRequestOptions} from '@angular/http'; | |
import {AppComponent} from './app.component'; | |
import {HomeComponent} from '../home/home.component'; | |
import {ProductsComponent} from '../products/products.component'; | |
import {AboutComponent} from '../about/about.component'; | |
import {LocationStrategy, HashLocationStrategy} from '@angular/common'; | |
import {routing} from './routes'; | |
@NgModule({ | |
providers: [ | |
BaseRequestOptions, | |
HttpModule, | |
{provide: LocationStrategy, useClass: HashLocationStrategy}, | |
], | |
imports: [BrowserModule, HttpModule, routing], | |
declarations: [ | |
AppComponent, | |
HomeComponent, | |
ProductsComponent, | |
AboutComponent | |
], | |
bootstrap: [AppComponent] | |
}) | |
export class AppModule { } |
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 {Routes, RouterModule} from '@angular/router'; | |
import {AppComponent} from './app.component'; | |
import {HomeComponent} from '../home/home.component'; | |
import {ProductsComponent} from '../products/products.component'; | |
import {AboutComponent} from '../about/about.component'; | |
const routes: Routes = [ | |
{path: '', redirectTo: '/home', pathMatch: 'full'}, | |
{path: 'home', component: HomeComponent}, | |
{path: 'products', component: ProductsComponent}, | |
{path: 'about', component: AboutComponent}, | |
]; | |
export const routing = RouterModule.forRoot(routes); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment