diff --git a/src/location/locationService.ts b/src/location/locationService.ts index ef18b4ac1..3a1ff8bc6 100644 --- a/src/location/locationService.ts +++ b/src/location/locationService.ts @@ -5,9 +5,9 @@ import { LocationStrategy } from '@angular/common'; /** A `LocationServices` that delegates to the Angular LocationStrategy */ export class Ng2LocationServices extends BaseLocationServices { - constructor(router: UIRouter, private _locationStrategy: LocationStrategy) { - super(router, true); - + constructor(router: UIRouter, private _locationStrategy: LocationStrategy, isBrowser: boolean) { + super(router, isBrowser); + this._locationStrategy.onPopState((evt) => { if (evt.type !== 'hashchange') { this._listener(evt); diff --git a/src/providers.ts b/src/providers.ts index 9b8d9e48b..d6313e7bf 100644 --- a/src/providers.ts +++ b/src/providers.ts @@ -85,10 +85,11 @@ * @preferred @module ng2 */ /** */ -import { Injector, Provider } from "@angular/core"; +import { Injector, Provider, PLATFORM_ID } from "@angular/core"; +import { isPlatformBrowser } from "@angular/common"; import { UIRouter, PathNode, StateRegistry, StateService, TransitionService, UrlMatcherFactory, UrlRouter, ViewService, - UrlService, UIRouterGlobals, services, Resolvable, NATIVE_INJECTOR_TOKEN + UrlService, UIRouterGlobals, services, Resolvable, NATIVE_INJECTOR_TOKEN, } from "@uirouter/core"; import { UIView, ParentUIViewInject } from "./directives/uiView"; import { ng2ViewsBuilder, Ng2ViewConfig } from "./statebuilders/views"; @@ -130,7 +131,7 @@ export function uiRouterFactory(locationStrategy: LocationStrategy, rootModules: // ----------------- Configure for ng2 ------------- - router.locationService = new Ng2LocationServices(router, locationStrategy); + router.locationService = new Ng2LocationServices(router, locationStrategy, isPlatformBrowser(injector.get(PLATFORM_ID))); router.locationConfig = new Ng2LocationConfig(router, locationStrategy); // Apply ng2 ui-view handling code