Skip to content

Commit 9b7e1e2

Browse files
ryansolidclaude
andauthored
docs(router): a leading slash is a full path under a base (#1686)
* docs(router): a leading slash is a full path under a base Matches solid-router#718 (@solidjs/router 2.0.0-next.44): navigate, links, useLinkState, useResolvedPath and redirect never add the router base to a path that starts with "/"; paths nodes include it. Adds the Vite BASE_URL setup note and the 0.x migration note. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0117BoWNSSgtemsSYsaX2hXE * docs(router): name 0.x/1.x in the base migration note Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0117BoWNSSgtemsSYsaX2hXE --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 10b6ee2 commit 9b7e1e2

5 files changed

Lines changed: 23 additions & 3 deletions

File tree

‎src/routes/(4)routing/(1)solid-router/(1)setup.mdx‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ The other options exist for a specific situation each:
120120

121121
| Option | Reach for it when |
122122
| ------------------- | --------------------------------------------------------------------------------------------------------------------------------- |
123-
| `base` | The app is served under a prefix such as `/app`; matching and `paths` both include it. |
123+
| `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. |
124124
| `history` | The app is not a normal page: an Electron shell or `file://` needs `hashHistory()`, tests need `memoryHistory()`. |
125125
| `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`. |
126126
| `preloadLinks` | Links should warm route code and data before the click; pass `intentPreload()` or another strategy (off by default). |
@@ -131,6 +131,16 @@ The other options exist for a specific situation each:
131131
| `singleFlight` | The router's server-function data consumer should be off; it is `true` by default. |
132132
| `actionBase` | Server functions are served from a prefix other than the default `/_server`. |
133133

134+
When Vite serves the app under a `base`, pass `import.meta.env.BASE_URL` as the router `base` and link with `paths`.
135+
A `paths` node includes the base, so links, `navigate`, and `redirect` stay under it:
136+
137+
```tsx
138+
export const Router = createRouter({
139+
routes,
140+
base: import.meta.env.BASE_URL,
141+
});
142+
```
143+
134144
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:
135145

136146
```tsx

‎src/routes/(4)routing/(1)solid-router/(4)navigation.mdx‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,10 @@ function CheckoutButton() {
9595
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.
9696

9797
The options are the same as the link attributes: `replace`, `scroll`, and `state`, plus `resolve` for how a relative string is interpreted.
98-
A string starting with `/` resolves under the router's `base`; other strings resolve against the current location like a relative URL.
98+
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`.
99+
Pass a `paths` node, such as `paths.about`, for a path under the base; a node already includes the base.
100+
A full path outside the base is another document, so `navigate` loads it, as a link or a redirect to it does.
101+
Other strings resolve against the current location like a relative URL.
99102
A number moves through history: `navigate(-1)` is back.
100103

101104
:::tip[Let the server decide where to go]

‎src/routes/(6)migration/(3)from-solid-router.mdx‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,12 @@ function LoginRedirect() {
296296
}
297297
```
298298

299+
Under a `base`, a string that starts with `/` is now a full path.
300+
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`.
301+
The same applies to `useResolvedPath`, `useLinkState`, and `redirect`.
302+
Use a `paths` node, such as `Router.paths.login`, which includes the base.
303+
A full path outside the base loads the document.
304+
299305
Rename `useCurrentMatches` to `useRouteMatches`.
300306
Use `useLinkState` when a custom link component needs reactive `active`, `current`, or `pending` values.
301307
See [Navigation and typed paths](/routing/solid-router/navigation) for the remaining anchor and navigation options.

‎src/routes/reference/(3)solid-router/(1)router-factory.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ interface RouterConfig<
5353
```
5454

5555
- `routes` is the route tree used for matching and path inference.
56-
- `base` prefixes matched and generated paths.
56+
- `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.
5757
- `preload` returns data for the root render prop.
5858
- `history` defaults to browser history on the client.
5959
- `singleFlight` defaults to `true`.

‎src/routes/reference/(3)solid-router/(3)navigation.mdx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ function useResolvedPath(path: () => string): () => string | undefined;
196196
```
197197

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

200201
## `useHref`
201202

0 commit comments

Comments
 (0)