Skip to content

Commit 22db6cb

Browse files
authored
feat: add typesafe pathname (#63)
1 parent 0aeafb1 commit 22db6cb

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

.changeset/rich-owls-laugh.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'sv-router': patch
3+
---
4+
5+
Add typesafe pathname

src/create-router.svelte.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export function createRouter(r) {
4646
return params.value;
4747
},
4848
get pathname() {
49-
return location.pathname;
49+
return /** @type {import('./index.d.ts').Path<T>} */ (location.pathname);
5050
},
5151
get search() {
5252
return location.search;

src/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ export type RouterApi<T extends Routes> = {
134134
*/
135135
params: AllParams<T>;
136136
/** The reactive pathname of the URL. */
137-
pathname: string;
137+
pathname: Path<T>;
138138
/** The reactive query string part of the URL. */
139139
search: string;
140140
/** The reactive history state that can be passed to the `navigate` function. */

0 commit comments

Comments
 (0)