When I open my Angular 2 app in a fresh browser window I get 10 entries in the browser page history. This happens on any page listed in the router and with no page specified (i.e. http://localhost:8080 or http://localhost:8080/survey etc)
const routes: Routes = [
{path: 'survey', component: SurveyComponent, canActivate: [AuthGuard]},
{path: 'survey/:id', component: SurveyComponent, canActivate: [AuthGuard]},
{path: '', component: HomeComponent},
{path: 'about', component: AboutComponent},
{path: 'terms', component: TermsAndConditionsComponent},
{path: 'map', component: MapComponent},
{path: 'what-next', component: WhatNextComponent},
{path: 'contact', component: ContactComponent},
{path: '**', redirectTo: '', pathMatch: 'full'},
];
I'm using router 3.1.2
"@angular/router": "3.1.2",
I have found a similar question from March last year but the answer claims it was solved in Angular's code already.
Update As requested, here is the AuthGuard code
import {Injectable} from '@angular/core';
import {AuthenticationService} from '../_services/index';
import {LoginModalService} from "../login_modal/login_modal.service";
import { Router, CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot} from '@angular/router';
import {Observable} from 'rxjs/Observable';
@Injectable()
export class AuthGuard implements CanActivate {
constructor(private authentication: AuthenticationService, private loginModalService: LoginModalService) {
}
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
if (this.authentication.isAuthenticated()) {
return Observable.of(true);
} else {
this.loginModalService.toggleVisable(state.url);
return Observable.of(false);
}
}
}