[FIX] router: preserve pathname in hash mode

closes #397
This commit is contained in:
Géry Debongnie
2019-10-27 21:11:11 +01:00
committed by Aaron Bohy
parent 5911c8e3f6
commit 2aa705f5c8
2 changed files with 10 additions and 1 deletions
+1 -1
View File
@@ -148,7 +148,7 @@ export class Router {
//--------------------------------------------------------------------------
private setUrlFromPath(path: string) {
const separator = this.mode === "hash" ? "/" : "";
const separator = this.mode === "hash" ? location.pathname : "";
const url = location.origin + separator + path;
if (url !== window.location.href) {
window.history.pushState({}, path, url);
+9
View File
@@ -52,6 +52,15 @@ describe("router miscellaneous", () => {
expect(window.location.hash).toBe("#/users/5");
expect(env.qweb.forceUpdate).toHaveBeenCalledTimes(2);
});
test("navigate in hash mode preserve location", async () => {
router = new TestRouter(env, [{ name: "users", path: "/users/{{id}}" }], {mode: "hash"});
window.history.pushState({}, "title", window.location.origin + '/test.html');
expect(window.location.href).toBe("http://localhost/test.html");
await router.navigate({ to: "users", params: { id: 3 } });
expect(window.location.href).toBe("http://localhost/test.html#/users/3");
});
});
describe("routeToPath", () => {