diff --git a/src/router.js b/src/router.js index 2e550a10..ccbb33f1 100644 --- a/src/router.js +++ b/src/router.js @@ -171,7 +171,7 @@ export class Router { } this.isExplicitNavigation = true; - return this.history.navigate(_resolveUrl(fragment, this.baseUrl, this.history._hasPushState), options); + return this.history.navigate(_resolveUrl(fragment, this.baseUrl, this.history._usePushState), options); } /** @@ -225,7 +225,7 @@ export class Router { } let path = this._recognizer.generate(name, params); - let rootedPath = _createRootedPath(path, this.baseUrl, this.history._hasPushState, options.absolute); + let rootedPath = _createRootedPath(path, this.baseUrl, this.history._usePushState, options.absolute); return options.absolute ? `${this.history.getAbsoluteRoot()}${rootedPath}` : rootedPath; } @@ -371,9 +371,9 @@ export class Router { for (let i = 0, length = nav.length; i < length; i++) { let current = nav[i]; if (!current.config.href) { - current.href = _createRootedPath(current.relativeHref, this.baseUrl, this.history._hasPushState); + current.href = _createRootedPath(current.relativeHref, this.baseUrl, this.history._usePushState); } else { - current.href = _normalizeAbsolutePath(current.config.href, this.history._hasPushState); + current.href = _normalizeAbsolutePath(current.config.href, this.history._usePushState); } } } diff --git a/src/util.js b/src/util.js index 6308932c..9446f76f 100644 --- a/src/util.js +++ b/src/util.js @@ -1,16 +1,16 @@ -export function _normalizeAbsolutePath(path, hasPushState, absolute = false) { - if (!hasPushState && path[0] !== '#') { +export function _normalizeAbsolutePath(path, usePushState, absolute = false) { + if (!usePushState && path[0] !== '#') { path = '#' + path; } - if (hasPushState && absolute) { + if (usePushState && absolute) { path = path.substring(1, path.length); } return path; } -export function _createRootedPath(fragment, baseUrl, hasPushState, absolute) { +export function _createRootedPath(fragment, baseUrl, usePushState, absolute) { if (isAbsoluteUrl.test(fragment)) { return fragment; } @@ -31,15 +31,15 @@ export function _createRootedPath(fragment, baseUrl, hasPushState, absolute) { path = path.substring(0, path.length - 1); } - return _normalizeAbsolutePath(path + fragment, hasPushState, absolute); + return _normalizeAbsolutePath(path + fragment, usePushState, absolute); } -export function _resolveUrl(fragment, baseUrl, hasPushState) { +export function _resolveUrl(fragment, baseUrl, usePushState) { if (isRootedPath.test(fragment)) { - return _normalizeAbsolutePath(fragment, hasPushState); + return _normalizeAbsolutePath(fragment, usePushState); } - return _createRootedPath(fragment, baseUrl, hasPushState); + return _createRootedPath(fragment, baseUrl, usePushState); } const isRootedPath = /^#?\//; diff --git a/test/router.spec.js b/test/router.spec.js index e61c6369..291eb757 100644 --- a/test/router.spec.js +++ b/test/router.spec.js @@ -82,7 +82,7 @@ describe('the router', () => { expect(child.generate('parent')).toBe('#/parent'); expect(child.generate('child')).toBe('#/child-router/child'); - router.history._hasPushState = true; + router.history._usePushState = true; expect(router.generate('parent')).toBe('/parent'); expect(child.generate('parent')).toBe('/parent'); @@ -123,7 +123,7 @@ describe('the router', () => { .then(() => { expect(child.generate('test', { id: 1 }, options)).toBe(`${absoluteRoot}#/test/1`); - router.history._hasPushState = true; + router.history._usePushState = true; expect(child.generate('test', { id: 1 }, options)).toBe(`${absoluteRoot}test/1`);