Skip to content

Commit 6bf8cd0

Browse files
authored
feat!: Replace implicitMode with defaultHash (#110)
BREAKING CHANGE
1 parent 597cdc0 commit 6bf8cd0

27 files changed

+2192
-99
lines changed

AGENTS.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ The @svelte-router/core routing library supports simultaneous path and hash rout
99
- **Path Routing** (`hash: false`): Uses URL pathname
1010
- **Single Hash Routing** (`hash: true`): Uses URL hash as a single path (e.g., `#/path/to/route`)
1111
- **Multi Hash Routing** (`hash: 'p1'`): Uses semicolon-separated hash segments (e.g., `#p1=/path;p2=/other`)
12-
- **Implicit Path Routing** (`hash: undefined`, `implicitMode: 'path'`): Resolves to path routing
13-
- **Implicit Hash Routing** (`hash: undefined`, `implicitMode: 'hash'`): Resolves to hash routing
12+
- **Implicit Path Routing** (`hash: undefined`, `defaultHash: false`): Resolves to path routing
13+
- **Implicit Hash Routing** (`hash: undefined`, `defaultHash: true`): Resolves to hash routing
14+
- **Implicit Named Hash Routing** (`hash: undefined`, `defaultHash: <a string>`): Resolves to named (multi) hash routing
1415

1516
#### Example Multi-Universe Setup
1617
```svelte
@@ -268,7 +269,7 @@ ROUTING_UNIVERSES.forEach((ru) => {
268269
let cleanup: () => void;
269270
beforeAll(() => {
270271
cleanup = init({
271-
implicitMode: ru.implicitMode,
272+
defaultHash: ru.defaultHash,
272273
hashMode: ru.hashMode
273274
});
274275
});
@@ -414,7 +415,7 @@ function bindablePropertyTests(setup: ReturnType<typeof createRouterTestSetup>,
414415
});
415416

416417
// Trigger binding based on routing mode
417-
const shouldUseHash = (ru.implicitMode === 'hash') || (hash === true) || (typeof hash === 'string');
418+
const shouldUseHash = (ru.defaultHash === true) || (hash === true) || (typeof hash === 'string');
418419
const url = shouldUseHash ? "http://example.com/#/test" : "http://example.com/test";
419420
location.url.href = url;
420421
await vi.waitFor(() => {});
@@ -579,7 +580,7 @@ test("Should bind route parameters correctly.", async () => {
579580
});
580581

581582
// Navigate to matching route
582-
const shouldUseHash = (ru.implicitMode === 'hash') || (hash === true) || (typeof hash === 'string');
583+
const shouldUseHash = (ru.defaultHash === true) || (hash === true) || (typeof hash === 'string');
583584
location.url.href = shouldUseHash ? "http://example.com/#/user/42" : "http://example.com/user/42";
584585
await vi.waitFor(() => {});
585586

@@ -816,7 +817,7 @@ ROUTING_UNIVERSES.forEach((universe) => {
816817

817818
beforeAll(() => {
818819
cleanup = init({
819-
implicitMode: universe.implicitMode,
820+
defaultHash: universe.defaultHash,
820821
hashMode: universe.hashMode
821822
});
822823
setup = createRouterTestSetup(universe.hash);

README.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
+ **Always-on path and hash routing**: Simultaneous, independent and always-on routing modes.
2323
+ **Multi hash routing**: Doing micro-frontends? Routing tabs or dialogs using the URL? Have as many paths as needed.
24-
+ **Sveltekit support**: Add hash routing on top of Sveltekit's path routing Via
24+
+ **Sveltekit support**: Add hash routing on top of Sveltekit's path routing via
2525
[@svelte-router/kit](https://github.com/WJSoftware/svelte-router-kit)
2626
+ **Electron support**: Works with Electron (all routing modes)
2727
+ **Reactivity-based**: All data is reactive, reducing the need for events and imperative programming.
@@ -43,7 +43,7 @@
4343
+ `RouterEngine.routes`
4444
+ `RouterEngine.routeStatus`
4545

46-
All data is a Svelte signal. Add routes dynamically or reactively, change route conditions on the fly, and more pieces
46+
All data is a Svelte signal. Add routes dynamically or reactively, change route conditions on the fly, add more pieces
4747
of user interface on-demand, etc. All works reactively.
4848

4949
### Two Library Modes
@@ -89,7 +89,7 @@ Default:
8989
init(); // Or use initFull() for full-mode.
9090

9191
// Common case: "I just need good, old-fashioned hash routing."
92-
init({ implicitMode: 'hash' });
92+
init({ defaultHash: true });
9393
```
9494

9595
#### Electron Variant
@@ -441,7 +441,7 @@ Additional `goTo()` options:
441441
1. **Use `<Link>` components** for user-triggered navigation
442442
2. **Use `navigate()`** for programmatic navigation within routing universes
443443
3. **Use `goTo()`** only for direct URL manipulation
444-
4. **Try to specify `hash`** in `navigate()` instead of relying on the implicit mode whenever possible
444+
4. **Try to specify `hash`** in `navigate()` instead of relying on the default hash whenever possible
445445

446446
Just in case you are wondering: This navigation logic is already there in `<Link>` components:
447447

@@ -461,8 +461,7 @@ As seen, the value of the `href` property never changes. It's always a path, re
461461

462462
> **⚠️ Important:** Not setting the `hash` property is **not the same** as setting it to `false`. When `hash` is
463463
> `undefined`, either because the property is not specified at all, or its value is set to `undefined` explicitly, the
464-
> value of the `implicitMode` library option, which is set when the library is initialized, will be used to resolve a
465-
> `true` or `false` value.
464+
> value of the `defaultHash` library option, which is set when the library is initialized, will be used instead.
466465
>
467466
> This is true for all components that support the `hash` property.
468467

0 commit comments

Comments
 (0)