Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix] match route against decoded path on client #2206

Merged
merged 1 commit into from
Aug 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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