Skip to content

Commit

Permalink
fix(router): browser history state not empty on new entries in IE/Edge
Browse files Browse the repository at this point in the history
The router doesn't handle the different behaviour in IE/Edge for history state on new entries. This fix consolidates the behaviour with Chrome etc.

Depending on PR aurelia/history-browser/history-state-consolidation.
Closes aurelia#489.
  • Loading branch information
jwx committed Apr 13, 2017
1 parent 507015e commit e4c7c2e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
8 changes: 4 additions & 4 deletions src/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);
}
}
}
Expand Down
16 changes: 8 additions & 8 deletions src/util.js
Original file line number Diff line number Diff line change
@@ -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;
}
Expand All @@ -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 = /^#?\//;
Expand Down
4 changes: 2 additions & 2 deletions test/router.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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`);

Expand Down

0 comments on commit e4c7c2e

Please sign in to comment.