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
12 changes: 11 additions & 1 deletion src/routes/(4)routing/(1)solid-router/(1)setup.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ The other options exist for a specific situation each:

| Option | Reach for it when |
| ------------------- | --------------------------------------------------------------------------------------------------------------------------------- |
| `base` | The app is served under a prefix such as `/app`; matching and `paths` both include it. |
| `base` | The app is served under a prefix such as `/app`; matching and `paths` include it, and a string starting with `/` is a full path. |
| `history` | The app is not a normal page: an Electron shell or `file://` needs `hashHistory()`, tests need `memoryHistory()`. |
| `preload` | The root layout needs data of its own; it runs once per mount or server request and reaches the function child as `props.data`. |
| `preloadLinks` | Links should warm route code and data before the click; pass `intentPreload()` or another strategy (off by default). |
Expand All @@ -131,6 +131,16 @@ The other options exist for a specific situation each:
| `singleFlight` | The router's server-function data consumer should be off; it is `true` by default. |
| `actionBase` | Server functions are served from a prefix other than the default `/_server`. |

When Vite serves the app under a `base`, pass `import.meta.env.BASE_URL` as the router `base` and link with `paths`.
A `paths` node includes the base, so links, `navigate`, and `redirect` stay under it:

```tsx
export const Router = createRouter({
routes,
base: import.meta.env.BASE_URL,
});
```

The router uses browser history by default on the client and the current request URL on the server, so `history` is rarely set in a web app:

```tsx
Expand Down
5 changes: 4 additions & 1 deletion src/routes/(4)routing/(1)solid-router/(4)navigation.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,10 @@ function CheckoutButton() {
Click the button and the URL becomes `/checkout` with the cart page's history entry replaced, so **Back** returns to the page before the cart rather than to the cart.

The options are the same as the link attributes: `replace`, `scroll`, and `state`, plus `resolve` for how a relative string is interpreted.
A string starting with `/` resolves under the router's `base`; other strings resolve against the current location like a relative URL.
A string starting with `/` is a full path, and the router does not add its `base` to it: under `base: "/app"`, `navigate("/about")` goes to `/about`.
Pass a `paths` node, such as `paths.about`, for a path under the base; a node already includes the base.
A full path outside the base is another document, so `navigate` loads it, as a link or a redirect to it does.
Other strings resolve against the current location like a relative URL.
A number moves through history: `navigate(-1)` is back.

:::tip[Let the server decide where to go]
Expand Down
6 changes: 6 additions & 0 deletions src/routes/(6)migration/(3)from-solid-router.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,12 @@ function LoginRedirect() {
}
```

Under a `base`, a string that starts with `/` is now a full path.
With `base: "/app"`, Solid Router 0.x/1.x sent `navigate("/login")` and `<A href="/login">` to `/app/login`; Solid Router 2 sends them to `/login`.
The same applies to `useResolvedPath`, `useLinkState`, and `redirect`.
Use a `paths` node, such as `Router.paths.login`, which includes the base.
A full path outside the base loads the document.

Rename `useCurrentMatches` to `useRouteMatches`.
Use `useLinkState` when a custom link component needs reactive `active`, `current`, or `pending` values.
See [Navigation and typed paths](/routing/solid-router/navigation) for the remaining anchor and navigation options.
Expand Down
2 changes: 1 addition & 1 deletion src/routes/reference/(3)solid-router/(1)router-factory.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ interface RouterConfig<
```

- `routes` is the route tree used for matching and path inference.
- `base` prefixes matched and generated paths.
- `base` prefixes route matching and `paths` nodes. A string that starts with `/` is a full path everywhere (`href`, `navigate`, `useLinkState`, `useResolvedPath`, and `redirect`), and the router does not add `base` to it.
- `preload` returns data for the root render prop.
- `history` defaults to browser history on the client.
- `singleFlight` defaults to `true`.
Expand Down
1 change: 1 addition & 0 deletions src/routes/reference/(3)solid-router/(3)navigation.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ function useResolvedPath(path: () => string): () => string | undefined;
```

Resolves a path against the current route context.
A path that starts with `/` is already a full path, so the router does not add its `base` to it.

## `useHref`

Expand Down
Loading