Skip to content

Instantly share code, notes, and snippets.

@DrDanL
Created May 11, 2018 09:15
Show Gist options
  • Save DrDanL/33397da6b3cc2055fb5a8eb72c8a2015 to your computer and use it in GitHub Desktop.
Save DrDanL/33397da6b3cc2055fb5a8eb72c8a2015 to your computer and use it in GitHub Desktop.
Example of canActiveRoutes.js in protecting routes using Firebase. See https://leightley.com/angular-2-and-firebase-authentication-route-guard/
import { ModuleWithProviders } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { AppComponent } from './app.component';
import { AuthGuard } from "./services/authGuard.service";
import { LoginComponent } from "./views/login/login.component";
import { SignupComponent } from './views/signup/signup.component';
import { DashboardComponent } from "./views/dashboard/dashboard.component";
export const router: Routes = [
{ path: '', redirectTo: 'dashboard', pathMatch: 'full' },
{ path: 'login', component: LoginComponent },
{ path: 'signup', component: SignupComponent },
{ path: 'dashboard', component: DashboardComponent, canActivate: [AuthGuard] },
]
export const AppRoutes: ModuleWithProviders = RouterModule.forRoot(router);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment