Skip to content

Commit b560677

Browse files
committed
Merge branch 'Nested-routing-refactor-&-Navigation-Guards' of https://github.com/notnotsamuel/svelte-tiny-router into Nested-routing-refactor-&-Navigation-Guards
2 parents 3543af3 + 1094913 commit b560677

File tree

2 files changed

+3
-5
lines changed

2 files changed

+3
-5
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ Here's a basic example demonstrating simple routes:
9494
<button on:click={navigateWithQuery}>Search</button>
9595
```
9696

97-
### get query strings
97+
### get then remove query strings
9898
```svelte
9999
<!-- SomeComponent.svelte -->
100100
<script>
@@ -107,6 +107,7 @@ Here's a basic example demonstrating simple routes:
107107
// Check if the "foo" query parameter exists (i.e /myroute?foo=bar) and log it
108108
if (router.hasQueryParam('foo')) {
109109
console.log("Value of foo:", router.getQueryParam('foo'));
110+
router.removeQueryParams(["foo"]);
110111
}
111112
112113
// Get a specific query parameter

src/lib/Router.svelte

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
66
const parentRouterContext = getContext('router'); // Might be undefined if this is the root router
77
8-
// --- BEGIN MODIFIED SECTION FOR EARLY QUERY PARSING ---
98
let initialQuery = {};
109
let initialFullPath = '/';
1110
@@ -19,7 +18,6 @@
1918
initialQuery = _parseQuery('?' + parts[1]);
2019
}
2120
}
22-
// --- END MODIFIED SECTION FOR EARLY QUERY PARSING ---
2321
2422
let initialBase = '/';
2523
let initialRelativePath = initialFullPath;
@@ -150,7 +148,7 @@
150148
// If url prop was used, initialQuery has it. Otherwise, it's {}.
151149
}
152150
}
153-
151+
154152
function removeQueryParams(keysToRemove) {
155153
if (typeof window !== 'undefined') {
156154
const currentSearch = window.location.search; // Get current query from actual URL
@@ -242,7 +240,6 @@
242240
router.getQueryParam = (key) => router.query[key];
243241
router.hasQueryParam = (key) => Object.prototype.hasOwnProperty.call(router.query, key);
244242
router.removeQueryParams = removeQueryParams;
245-
246243
setContext('router', router);
247244
</script>
248245

0 commit comments

Comments
 (0)