Skip to content

Commit

Permalink
[fix] match route against decoded path on client (#2206)
Browse files Browse the repository at this point in the history
  • Loading branch information
benmccann authored Aug 14, 2021
1 parent 6a8b6a6 commit 930ef8e
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .changeset/clever-pillows-sing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

[fix] match route against decoded path on client
9 changes: 4 additions & 5 deletions packages/kit/src/runtime/client/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -363,8 +363,7 @@ export class Renderer {
const result = await this._load(
{
route,
path: info.path,
query: info.query
info
},
no_cache
);
Expand Down Expand Up @@ -540,8 +539,8 @@ export class Renderer {
* @param {boolean} no_cache
* @returns {Promise<import('./types').NavigationResult | undefined>} undefined if fallthrough
*/
async _load({ route, path, query }, no_cache) {
const key = `${path}?${query}`;
async _load({ route, info: { path, decoded_path, query } }, no_cache) {
const key = `${decoded_path}?${query}`;

if (!no_cache) {
const cached = this.cache.get(key);
Expand All @@ -550,7 +549,7 @@ export class Renderer {

const [pattern, a, b, get_params] = route;
// @ts-expect-error - the pattern is for the route which we've already matched to this path
const params = get_params ? get_params(pattern.exec(path)) : {};
const params = get_params ? get_params(pattern.exec(decoded_path)) : {};

const changed = this.current.page && {
path: path !== this.current.page.path,
Expand Down
6 changes: 3 additions & 3 deletions packages/kit/src/runtime/client/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,13 +170,13 @@ export class Router {
if (this.owns(url)) {
const path = url.pathname.slice(this.base.length) || '/';

const decoded = decodeURI(path);
const routes = this.routes.filter(([pattern]) => pattern.test(decoded));
const decoded_path = decodeURI(path);
const routes = this.routes.filter(([pattern]) => pattern.test(decoded_path));

const query = new URLSearchParams(url.search);
const id = `${path}?${query}`;

return { id, routes, path, query };
return { id, routes, path, decoded_path, query };
}
}

Expand Down
4 changes: 2 additions & 2 deletions packages/kit/src/runtime/client/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ export type NavigationInfo = {
id: string;
routes: CSRRoute[];
path: string;
decoded_path: string;
query: URLSearchParams;
};

export type NavigationCandidate = {
route: CSRPage;
path: string;
query: URLSearchParams;
info: NavigationInfo;
};

export type NavigationResult = {
Expand Down

0 comments on commit 930ef8e

Please sign in to comment.