Skip to content

Commit f0792b7

Browse files
fix: introduce the missing navigation cancellation fix
1 parent 72eb556 commit f0792b7

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

.changeset/hot-pugs-worry.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
'sv-router': patch
33
---
44

5-
pass initial page pathname, search, hash to onNavigate, correctly handle cancellation of navigations, return Error in navigate
5+
correctly handle cancellation of navigations, return Error in navigate

src/create-router.svelte.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { BROWSER, DEV } from 'esm-env';
22
import { isActive } from './helpers/is-active.js';
33
import { matchRoute } from './helpers/match-route.js';
44
import { preload, preloadOnHover } from './helpers/preload.js';
5-
import { Navigation } from './navigation.js';
65
import {
76
constructPath,
87
constructUrl,
@@ -13,6 +12,7 @@ import {
1312
stripBase,
1413
updatedLocation,
1514
} from './helpers/utils.js';
15+
import { Navigation } from './navigation.js';
1616
import { syncSearchParams } from './search-params.svelte.js';
1717

1818
/** @type {import('./index.d.ts').Routes} */
@@ -134,7 +134,7 @@ function navigate(path, options = {}) {
134134
}
135135

136136
/**
137-
* @param {string} path
137+
* @param {string} [path]
138138
* @param {import('./index.d.ts').NavigateOptions} options
139139
*/
140140
export async function onNavigate(path, options = {}) {
@@ -145,7 +145,7 @@ export async function onNavigate(path, options = {}) {
145145
navigationIndex++;
146146
const currentNavigationIndex = navigationIndex;
147147

148-
let matchPath = getMatchPath(path);
148+
const matchPath = getMatchPath(path);
149149
const { match, layouts, hooks, meta: newMeta, params: newParams } = matchRoute(matchPath, routes);
150150

151151
const search = parseSearch(options.search);
@@ -179,7 +179,7 @@ export async function onNavigate(path, options = {}) {
179179
}
180180
if (
181181
navigationIndex !== currentNavigationIndex ||
182-
(fromBeforeLoadHook && pendingNavigationIndex + 1 !== currentNavigationIndex)
182+
(fromBeforeLoadHook && pendingNavigationIndex !== currentNavigationIndex)
183183
) {
184184
return;
185185
}

0 commit comments

Comments
 (0)