Skip to content

Commit

Permalink
feat: allow passing router to getNextPath
Browse files Browse the repository at this point in the history
  • Loading branch information
Uninen committed Jan 6, 2024
1 parent a5d8a42 commit 7f40c40
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
12 changes: 10 additions & 2 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
# Changelog

## 0.2.2 (2024-01-05)

- Feat: allow passing Router instance to `getNextPath`.

## 0.2.1 (2024-01-05)

- Fix: package.json is now more Vite -compatible.

## 0.2.0 (2024-01-05)

- Feat: added `getNextPath`
- Refactor: refactored internals
- Feat: added `getNextPath`.
- Refactor: refactored internals.
- Chore: bumped deps.

## 0.1.2 (2023-07-17)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ General utilities for Web development

### Vue

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

## Installation

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@slipmatio/toolbelt",
"type": "module",
"version": "0.2.1",
"version": "0.2.2",
"main": "dist/toolbelt.umd.cjs",
"module": "dist/toolbelt.js",
"exports": {
Expand Down
12 changes: 9 additions & 3 deletions src/routes.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import { useRoute } from 'vue-router'
import { useRoute, type Router, type RouteLocationNormalizedLoaded } from 'vue-router'
import { isString } from './type-helpers'

/**
* Helper for figuring our ?next= query param in a safe way.
* Pass the router instance whenever not used directly from script setup block.
*/
export function getNextPath(): string {
const route = useRoute()
export function getNextPath(router?: Router): string {
let route: RouteLocationNormalizedLoaded
if (router) {
route = router.currentRoute.value
} else {
route = useRoute()
}

let next = '/'
if (
Expand Down

0 comments on commit 7f40c40

Please sign in to comment.