sv-router 0.7.0 → 0.7.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sv-router",
3
- "version": "0.7.0",
3
+ "version": "0.7.1",
4
4
  "description": "Modern Svelte Routing",
5
5
  "keywords": [
6
6
  "svelte",
@@ -38,6 +38,9 @@
38
38
  "devDependencies": {
39
39
  "@changesets/cli": "^2.29.4",
40
40
  "@eslint/js": "^9.28.0",
41
+ "@sveltejs/vite-plugin-svelte": "^5.1.0",
42
+ "@testing-library/jest-dom": "^6.6.3",
43
+ "@testing-library/svelte": "^5.2.8",
41
44
  "@types/node": "^22.15.30",
42
45
  "eslint": "^9.28.0",
43
46
  "eslint-config-prettier": "^10.1.5",
@@ -45,6 +48,7 @@
45
48
  "eslint-plugin-svelte": "^3.9.1",
46
49
  "eslint-plugin-unicorn": "^59.0.1",
47
50
  "globals": "^16.2.0",
51
+ "jsdom": "^26.1.0",
48
52
  "prettier": "^3.5.3",
49
53
  "prettier-plugin-jsdoc": "^1.3.2",
50
54
  "prettier-plugin-svelte": "^3.4.0",
@@ -52,7 +56,7 @@
52
56
  "type-testing": "^0.2.0",
53
57
  "typescript": "^5.8.3",
54
58
  "typescript-eslint": "^8.33.1",
55
- "vite": "^6.3.5",
59
+ "vite": "^7.0.0",
56
60
  "vitest": "^3.2.2"
57
61
  },
58
62
  "peerDependencies": {
@@ -1,4 +1,5 @@
1
- import { location } from './create-router.svelte.js';
1
+ import { base, location } from './create-router.svelte.js';
2
+ import { join } from './helpers/utils.js';
2
3
 
3
4
  /** @type {import('./index.d.ts').IsActiveLink} */
4
5
  export function isActiveLink(node, { className = 'is-active', startsWith = false } = {}) {
@@ -7,7 +8,10 @@ export function isActiveLink(node, { className = 'is-active', startsWith = false
7
8
  }
8
9
 
9
10
  $effect(() => {
10
- const pathname = new URL(node.href).pathname;
11
+ let pathname = new URL(node.href).pathname;
12
+ if (base.name) {
13
+ pathname = join(base.name, pathname);
14
+ }
11
15
  if (startsWith ? location.pathname.startsWith(pathname) : location.pathname === pathname) {
12
16
  node.classList.add(className);
13
17
  } else {
@@ -1,5 +1,5 @@
1
- import { location } from '../create-router.svelte.js';
2
- import { constructPath } from './utils.js';
1
+ import { base, location } from '../create-router.svelte.js';
2
+ import { constructPath, join } from './utils.js';
3
3
 
4
4
  /**
5
5
  * @param {string} pathname
@@ -7,7 +7,8 @@ import { constructPath } from './utils.js';
7
7
  * @returns {boolean}
8
8
  */
9
9
  export function isActive(pathname, params) {
10
- return compare((a, b) => a === b, pathname, params);
10
+ const p = base.name ? join(base.name, pathname) : pathname;
11
+ return compare((a, b) => a === b, p, params);
11
12
  }
12
13
 
13
14
  /**
@@ -16,7 +17,8 @@ export function isActive(pathname, params) {
16
17
  * @returns {boolean}
17
18
  */
18
19
  isActive.startsWith = (pathname, params) => {
19
- return compare((a, b) => a.startsWith(b), pathname, params);
20
+ const p = base.name ? join(base.name, pathname) : pathname;
21
+ return compare((a, b) => a.startsWith(b), p, params);
20
22
  };
21
23
 
22
24
  /**
@@ -36,6 +38,9 @@ function compare(compareFn, pathname, params) {
36
38
 
37
39
  const pathParts = pathname.split('/').slice(1);
38
40
  const routeParts = location.pathname.split('/').slice(1);
41
+ if (pathParts.length > routeParts.length) {
42
+ return false;
43
+ }
39
44
  for (const [index, pathPart] of pathParts.entries()) {
40
45
  const routePart = routeParts[index];
41
46
  if (pathPart.startsWith(':')) {