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 Sep 19, 2018
1 parent 8d20410 commit cd4c90b
Show file tree
Hide file tree
Showing 3 changed files with 16 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 @@ -230,7 +230,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 @@ -285,7 +285,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 @@ -437,9 +437,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);
}

export function _ensureArrayWithSingleRoutePerConfig(config) {
Expand Down
6 changes: 4 additions & 2 deletions test/router.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,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 @@ -136,7 +136,9 @@ describe('the router', () => {
.then(() => {
expect(child.generate('test', { id: 1 }, options)).toBe(`${absoluteRoot}#/test/1`);
expect(child.generate('parent', { id: 2 }, options)).toBe(`${absoluteRoot}#/parent/2`);
router.history._hasPushState = true;

router.history._usePushState = true;

expect(child.generate('test', { id: 1 }, options)).toBe(`${absoluteRoot}test/1`);
expect(child.generate('parent', { id: 2 }, options)).toBe(`${absoluteRoot}parent/2`);
done();
Expand Down

0 comments on commit cd4c90b

Please sign in to comment.