-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(location): make initial otherwise('/') activate state (perform ur…
…l sync) refactor(location) move location code to /location/* refactor(plugins): Switch to plugins API feat(UrlService): Add UrlService injectable Closes #17
- Loading branch information
1 parent
cb7f51f
commit 33ae6a8
Showing
7 changed files
with
131 additions
and
132 deletions.
There are no files selected for viewing
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
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
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/** @module ng2 */ | ||
/** */ | ||
|
||
import { UIRouter, is, isDefined } from "ui-router-core"; | ||
import { PlatformLocation, LocationStrategy, PathLocationStrategy } from "@angular/common"; | ||
|
||
export class Ng2LocationConfig { | ||
private _isHtml5: boolean; | ||
private _hashPrefix: string = ""; | ||
|
||
constructor(router: UIRouter, locationStrategy: LocationStrategy, public platformLocation: PlatformLocation) { | ||
this._isHtml5 = is(PathLocationStrategy)(locationStrategy); | ||
} | ||
|
||
dispose() {} | ||
port = () => null as number; | ||
protocol = () => null as string; | ||
host = () => null as string; | ||
baseHref = () => this.platformLocation.getBaseHrefFromDOM(); | ||
html5Mode = () => this._isHtml5; | ||
hashPrefix = (newprefix?: string): string => { | ||
if(isDefined(newprefix)) { | ||
this._hashPrefix = newprefix; | ||
} | ||
return this._hashPrefix; | ||
}; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/** @module ng2 */ | ||
/** */ | ||
import { UIRouter } from "ui-router-core"; | ||
import { BaseLocationServices } from "ui-router-core/lib/vanilla"; | ||
import { parseUrl } from "ui-router-core/lib/vanilla/utils"; | ||
import { PlatformLocation, LocationStrategy } from "@angular/common"; | ||
|
||
/** A `LocationServices` that uses the browser hash "#" to get/set the current location */ | ||
export class Ng2LocationServices extends BaseLocationServices { | ||
constructor(router: UIRouter, private _locationStrategy: LocationStrategy, private _platform: PlatformLocation) { | ||
super(router, true); | ||
this._locationStrategy.onPopState(this._listener) | ||
} | ||
|
||
_get() { | ||
return this._locationStrategy.path(true); | ||
} | ||
|
||
_set(state: any, title: string, url: string, replace: boolean): any { | ||
let { path, search, hash } = parseUrl(url); | ||
let urlWithHash = path + (hash ? "#" + hash : ""); | ||
|
||
if (replace) { | ||
this._locationStrategy.replaceState(state, title, urlWithHash, search); | ||
} else { | ||
this._locationStrategy.pushState(state, title, urlWithHash, search); | ||
} | ||
} | ||
|
||
dispose (router: UIRouter) { | ||
super.dispose(router); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/** @module ng2 */ | ||
/** */ | ||
import { PlatformLocation, LocationStrategy } from "@angular/common"; | ||
import { Injectable } from "@angular/core"; | ||
import { UIRouter } from "ui-router-core"; | ||
import { Ng2LocationConfig } from "./locationConfig"; | ||
import { Ng2LocationServices } from "./locationService"; | ||
|
||
@Injectable() | ||
export class UIRouterLocation { | ||
constructor(public locationStrategy: LocationStrategy, public platformLocation: PlatformLocation ) { } | ||
|
||
init(router: UIRouter) { | ||
router.locationService = new Ng2LocationServices(router, this.locationStrategy, this.platformLocation); | ||
router.locationConfig = new Ng2LocationConfig(router, this.locationStrategy, this.platformLocation) | ||
} | ||
} | ||
|
||
|
||
|
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