Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
> + Always-on path and hash routing. Simultaneous and independent routing modes.
> + The router that invented multi hash routing.

+ **Electron support**: Works with Electron (all routing modes)
+ **Reactivity-based**: All data is reactive, reducing the need for events and imperative programming.
+ **Always-on path and hash routing**: Add routers that use the URL's path name or the URL's hash value in the same
application. Both routing modes are possible simultaneously.
Expand Down Expand Up @@ -107,6 +108,21 @@ init();
init({ implicitMode: 'hash' });
```

#### Electron Variant

In Electron, we must immediately navigate to the homepage (or your preferred initial route) right after initializing if you use path routing:

```typescript
import { init, location } from "@wjfe/n-savant";

init();
location.goTo('/');
```

For applications that also run in the browser, condition the navigation to Electron only. See the [Electron page](https://wjfe-n-savant.hashnode.space/wjfe-n-savant/introduction/electron-support) online for more details.

> **⚠️ Important:** Hash routing doesn't require this extra step.

### Define the Routes

`<Route>`s are added inside `<Router>`s. `<Router>`s can be nested inside other `<Router>`s. `<Route>`s can render
Expand Down
12 changes: 11 additions & 1 deletion src/lib/core/RouterEngine.svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export class RouterEngine {
return this.#routePatterns;
}

#testPath = $derived.by(() => noTrailingSlash(this.#hashId ? (location.hashPaths[this.#hashId] || '/') : this.url.pathname));
#testPath = $derived.by(() => noTrailingSlash(this.#hashId ? (location.hashPaths[this.#hashId] || '/') : this.path));

#routeStatusData = $derived.by(() => {
const routeStatus = {} as Record<string, RouteStatus>;
Expand Down Expand Up @@ -243,6 +243,16 @@ export class RouterEngine {
get url() {
return location.url;
}
/**
* Gets the environment's current path.
*
* This is a sanitized version of `location.url.pathname` that strips out drive letters for the case of Electron in
* Windows. It is highly recommended to always use this path whenever possible.
*/
get path() {
const hasDriveLetter = this.url.protocol.startsWith('file:') && this.url.pathname[2] === ':';
return hasDriveLetter ? this.url.pathname.substring(3) : this.url.pathname;
}
/**
* Gets the browser's current state.
*
Expand Down