next-use-contextual-routing 4.0.0 → 4.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +2 -1
  2. package/dist/index.js +14 -3
  3. package/package.json +18 -19
package/README.md CHANGED
@@ -106,6 +106,7 @@ const makeContextualHref: (
106
106
  The function returns the path to provide as `href` to start or keep alive contextual navigation. The generated path describes the state of the page to keep alive while contextual navigation is active.
107
107
 
108
108
  It optionally accepts an object describing **extra parameters** to append to contextual navigation `href`.
109
+ Array values from the current router query, such as catch-all route segments, are serialized as repeated query parameters. Since a query string can't express a one-item array, a single-segment catch-all reaches the page as a string: normalize it with `[router.query.slug].flat()`. Extra parameters replace existing query values with the same key.
109
110
 
110
111
  #### returnHref
111
112
 
@@ -122,7 +123,7 @@ The path to return to to close contextual navigation.
122
123
  | v2.2.0 | v9.X -> v12.X |
123
124
  | v3.0.0 | v13.X |
124
125
  | v3.2.0 + | v13.X -> v14.X |
125
- | v4.0.0 + | v15.X |
126
+ | v4.0.0 + | v15.X -> v16.X |
126
127
 
127
128
  ## Notes
128
129
 
package/dist/index.js CHANGED
@@ -25,8 +25,19 @@ export function useContextualRouting() {
25
25
  const returnHref = returnHrefQueryParam !== null && returnHrefQueryParam !== void 0 ? returnHrefQueryParam : router.asPath;
26
26
  // @NOTE JSON.stringify might be replaced with any hashing solution
27
27
  const queryHash = JSON.stringify(watchedQuery);
28
- const makeContextualHref = useCallback((extraParams) => router.pathname +
29
- '?' +
30
- new URLSearchParams(Object.assign(Object.assign(Object.assign({}, router.query), extraParams), { [RETURN_HREF_QUERY_PARAM]: returnHref })).toString(), [queryHash, returnHref]);
28
+ const makeContextualHref = useCallback((extraParams) => {
29
+ const params = new URLSearchParams();
30
+ const query = Object.assign(Object.assign(Object.assign({}, router.query), extraParams), { [RETURN_HREF_QUERY_PARAM]: returnHref });
31
+ for (const [key, value] of Object.entries(query)) {
32
+ if (Array.isArray(value)) {
33
+ for (const item of value)
34
+ params.append(key, item);
35
+ }
36
+ else {
37
+ params.append(key, String(value));
38
+ }
39
+ }
40
+ return router.pathname + '?' + params.toString();
41
+ }, [queryHash, returnHref]);
31
42
  return { returnHref, makeContextualHref };
32
43
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "next-use-contextual-routing",
3
3
  "description": "Generate Next.js contextual routing paths",
4
- "version": "4.0.0",
4
+ "version": "4.1.1",
5
5
  "keywords": [
6
6
  "next",
7
7
  "next.js",
@@ -29,15 +29,10 @@
29
29
  "access": "public"
30
30
  },
31
31
  "scripts": {
32
- "clean": "rm -rf dist",
33
- "build": "npm run clean && tsc -p tsconfig.build.json",
34
- "preversion": "npm run prepare",
35
- "version": "git add package.json",
36
- "postversion": "git push && git push --tags",
37
- "prepare": "npx simple-git-hooks && npm run source:check && npm run test -- --run && npm run build",
32
+ "build": "rimraf ./dist && tsc -p tsconfig.build.json",
38
33
  "test": "vitest --config ./vitest.config.mts",
39
- "test:a": "vitest --config ./vitest.config.mts",
40
- "tag": "node ./scripts/tag.js",
34
+ "prepare": "npx simple-git-hooks && npm run source:check && npm run test -- --run && npm run build",
35
+ "release": "npm run prepare && npx changeset publish",
41
36
  "prettier:check": "prettier . --check",
42
37
  "prettier:fix": "npm run prettier:check -- --write",
43
38
  "type:check": "tsc --noEmit",
@@ -48,24 +43,28 @@
48
43
  "demo:build": "npm run build && cd ./demo && BUILD_TARGET=github-pages next build && touch ./out/.nojekyll"
49
44
  },
50
45
  "devDependencies": {
51
- "@changesets/cli": "^2.27.7",
46
+ "@changesets/changelog-github": "^1.0.1",
47
+ "@changesets/cli": "^3.0.3",
52
48
  "@testing-library/react": "^16.0.0",
53
49
  "@tsconfig/node20": "^20.1.4",
54
- "@types/react": "^18.0.25",
55
- "@vitest/coverage-v8": "^2.1.3",
56
- "next": "^15.0.0",
57
- "prettier": "^3.3.2",
50
+ "@types/node": "^20.19.0",
51
+ "@types/react": "^19.1.6",
52
+ "@vitest/coverage-v8": "^4.0.0",
53
+ "jsdom": "^29.0.1",
54
+ "next": "^16.0.0",
55
+ "prettier": "^3.9.6",
58
56
  "qs-stringify": "^1.2.1",
59
- "react": "^18.2.0",
60
- "react-dom": "^18.2.0",
57
+ "react": "^19.1.0",
58
+ "react-dom": "^19.1.0",
61
59
  "react-modal": "^3.16.1",
62
- "react-test-renderer": "^18.2.0",
60
+ "react-test-renderer": "^19.1.0",
61
+ "rimraf": "^6.0.1",
63
62
  "simple-git-hooks": "^2.11.1",
64
63
  "typescript": "^5.5.3",
65
- "vitest": "^2.1.3"
64
+ "vitest": "^4.0.0"
66
65
  },
67
66
  "peerDependencies": {
68
- "next": "^15.0.0",
67
+ "next": "^15.0.0 || ^16.0.0",
69
68
  "react": ">=18.0.0"
70
69
  },
71
70
  "simple-git-hooks": {