Skip to content

Commit 7f40c40

Browse files
committed
feat: allow passing router to getNextPath
1 parent a5d8a42 commit 7f40c40

File tree

4 files changed

+21
-7
lines changed

4 files changed

+21
-7
lines changed

CHANGES.md

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
# Changelog
22

3+
## 0.2.2 (2024-01-05)
4+
5+
- Feat: allow passing Router instance to `getNextPath`.
6+
7+
## 0.2.1 (2024-01-05)
8+
9+
- Fix: package.json is now more Vite -compatible.
10+
311
## 0.2.0 (2024-01-05)
412

5-
- Feat: added `getNextPath`
6-
- Refactor: refactored internals
13+
- Feat: added `getNextPath`.
14+
- Refactor: refactored internals.
715
- Chore: bumped deps.
816

917
## 0.1.2 (2023-07-17)

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ General utilities for Web development
1414

1515
### Vue
1616

17-
- `getNextPath(): string` - returns the value of `?next` query param or `/`
17+
- `getNextPath(router?: Router): string` - returns the value of `?next` query param or `/`
1818

1919
## Installation
2020

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@slipmatio/toolbelt",
33
"type": "module",
4-
"version": "0.2.1",
4+
"version": "0.2.2",
55
"main": "dist/toolbelt.umd.cjs",
66
"module": "dist/toolbelt.js",
77
"exports": {

src/routes.ts

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
1-
import { useRoute } from 'vue-router'
1+
import { useRoute, type Router, type RouteLocationNormalizedLoaded } from 'vue-router'
22
import { isString } from './type-helpers'
33

44
/**
55
* Helper for figuring our ?next= query param in a safe way.
6+
* Pass the router instance whenever not used directly from script setup block.
67
*/
7-
export function getNextPath(): string {
8-
const route = useRoute()
8+
export function getNextPath(router?: Router): string {
9+
let route: RouteLocationNormalizedLoaded
10+
if (router) {
11+
route = router.currentRoute.value
12+
} else {
13+
route = useRoute()
14+
}
915

1016
let next = '/'
1117
if (

0 commit comments

Comments
 (0)