-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
docs(start): document route and asset base paths #7882
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
whizzkid1452
wants to merge
2
commits into
TanStack:main
Choose a base branch
from
whizzkid1452:bug/start-basepath-docs
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| --- | ||
| id: base-paths | ||
| title: Base Paths | ||
| --- | ||
|
|
||
| # Base Paths | ||
|
|
||
| Use base paths when your application or its assets are served below the origin root. TanStack Start has two separate settings: | ||
|
|
||
| - Vite's `base` controls the public URL prefix for assets, such as JavaScript and CSS. | ||
| - Start's `router.basepath` controls the URL prefix for application routes and server functions. | ||
|
|
||
| Configure these settings in `vite.config.ts`. Do not rely on the router instance in `src/router.tsx` to configure a Start base path. | ||
|
|
||
| ## Serve the Application and Assets from the Same Path | ||
|
|
||
| For example, to serve the application and its assets from `/app/`, set both options to the same path: | ||
|
|
||
| ```ts | ||
| // vite.config.ts | ||
| import { defineConfig } from 'vite' | ||
| import { tanstackStart } from '@tanstack/react-start/plugin/vite' | ||
| import viteReact from '@vitejs/plugin-react' | ||
|
|
||
| export default defineConfig({ | ||
| base: '/app/', | ||
| plugins: [ | ||
| tanstackStart({ | ||
| router: { | ||
| basepath: '/app', | ||
| }, | ||
| }), | ||
| viteReact(), | ||
| ], | ||
| }) | ||
| ``` | ||
|
|
||
| `serverFns.base` defaults to `/_serverFn`. Start appends it to `router.basepath` to form the server-function URL prefix, so the configuration above uses `/app/_serverFn`. | ||
|
|
||
| This configuration produces URLs with the following responsibilities: | ||
|
|
||
| | URL | Prefix source | | ||
| | -------------------- | -------------------------------------- | | ||
| | `/app/about` | `router.basepath` | | ||
| | `/app/_serverFn/...` | `router.basepath` and `serverFns.base` | | ||
| | `/app/assets/...` | Vite `base` | | ||
|
|
||
| If you omit `router.basepath`, Start derives it from a path-based Vite `base`. Setting both explicitly can make the deployment contract easier to see. | ||
|
|
||
| Your development server handles this configuration automatically. In production, configure your server or reverse proxy to forward `/app/*` to the Start application and serve the client assets at the same prefix. | ||
|
|
||
| ## Use Different Paths for Routes and Assets | ||
|
|
||
| You can keep application routes at the origin root while serving assets from another path. Set Vite's `base` to the asset prefix and set `router.basepath` explicitly to `/`: | ||
|
|
||
| ```ts | ||
| // vite.config.ts | ||
| import { defineConfig } from 'vite' | ||
| import { tanstackStart } from '@tanstack/react-start/plugin/vite' | ||
| import viteReact from '@vitejs/plugin-react' | ||
|
|
||
| export default defineConfig({ | ||
| base: '/_ui/', | ||
| plugins: [ | ||
| tanstackStart({ | ||
| router: { | ||
| basepath: '/', | ||
| }, | ||
| }), | ||
| viteReact(), | ||
| ], | ||
| }) | ||
| ``` | ||
|
|
||
| This configuration produces application routes such as `/` and `/about`, while JavaScript and CSS URLs begin with `/_ui/`. | ||
|
|
||
| In production, make both URL spaces available: | ||
|
|
||
| - Forward application routes such as `/about` to the Start server. | ||
| - Serve or forward asset requests under `/_ui/`. | ||
|
|
||
| ## Verify the Configuration | ||
|
|
||
| Check both direct requests and client-side navigation: | ||
|
|
||
| 1. Open the application at its configured route base. | ||
| 2. Navigate with a `Link` and confirm that the route URL contains `router.basepath`, not Vite's `base`. | ||
| 3. Inspect script and stylesheet URLs and confirm that they contain Vite's `base`. | ||
| 4. Load a nested route directly to verify that the production server forwards it correctly. | ||
|
|
||
| For runtime asset rewriting with a Content Delivery Network (CDN), see [CDN Asset URLs](./cdn-asset-urls). | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| --- | ||
| id: base-paths | ||
| title: Base Paths | ||
| --- | ||
|
|
||
| # Base Paths | ||
|
|
||
| Use base paths when your application or its assets are served below the origin root. TanStack Start has two separate settings: | ||
|
|
||
| - Vite's `base` controls the public URL prefix for assets, such as JavaScript and CSS. | ||
| - Start's `router.basepath` controls the URL prefix for application routes and server functions. | ||
|
|
||
| Configure these settings in `vite.config.ts`. Do not rely on the router instance in `src/router.tsx` to configure a Start base path. | ||
|
|
||
| ## Serve the Application and Assets from the Same Path | ||
|
|
||
| For example, to serve the application and its assets from `/app/`, set both options to the same path: | ||
|
|
||
| ```ts | ||
| // vite.config.ts | ||
| import { defineConfig } from 'vite' | ||
| import { tanstackStart } from '@tanstack/solid-start/plugin/vite' | ||
| import viteSolid from 'vite-plugin-solid' | ||
|
|
||
| export default defineConfig({ | ||
| base: '/app/', | ||
| plugins: [ | ||
| tanstackStart({ | ||
| router: { | ||
| basepath: '/app', | ||
| }, | ||
| }), | ||
| viteSolid({ ssr: true }), | ||
| ], | ||
| }) | ||
| ``` | ||
|
|
||
| `serverFns.base` defaults to `/_serverFn`. Start appends it to `router.basepath` to form the server-function URL prefix, so the configuration above uses `/app/_serverFn`. | ||
|
|
||
| This configuration produces URLs with the following responsibilities: | ||
|
|
||
| | URL | Prefix source | | ||
| | -------------------- | -------------------------------------- | | ||
| | `/app/about` | `router.basepath` | | ||
| | `/app/_serverFn/...` | `router.basepath` and `serverFns.base` | | ||
| | `/app/assets/...` | Vite `base` | | ||
|
|
||
| If you omit `router.basepath`, Start derives it from a path-based Vite `base`. Setting both explicitly can make the deployment contract easier to see. | ||
|
|
||
| Your development server handles this configuration automatically. In production, configure your server or reverse proxy to forward `/app/*` to the Start application and serve the client assets at the same prefix. | ||
|
|
||
| ## Use Different Paths for Routes and Assets | ||
|
|
||
| You can keep application routes at the origin root while serving assets from another path. Set Vite's `base` to the asset prefix and set `router.basepath` explicitly to `/`: | ||
|
|
||
| ```ts | ||
| // vite.config.ts | ||
| import { defineConfig } from 'vite' | ||
| import { tanstackStart } from '@tanstack/solid-start/plugin/vite' | ||
| import viteSolid from 'vite-plugin-solid' | ||
|
|
||
| export default defineConfig({ | ||
| base: '/_ui/', | ||
| plugins: [ | ||
| tanstackStart({ | ||
| router: { | ||
| basepath: '/', | ||
| }, | ||
| }), | ||
| viteSolid({ ssr: true }), | ||
| ], | ||
| }) | ||
| ``` | ||
|
|
||
| This configuration produces application routes such as `/` and `/about`, while JavaScript and CSS URLs begin with `/_ui/`. | ||
|
|
||
| In production, make both URL spaces available: | ||
|
|
||
| - Forward application routes such as `/about` to the Start server. | ||
| - Serve or forward asset requests under `/_ui/`. | ||
|
|
||
| ## Verify the Configuration | ||
|
|
||
| Check both direct requests and client-side navigation: | ||
|
|
||
| 1. Open the application at its configured route base. | ||
| 2. Navigate with a `Link` and confirm that the route URL contains `router.basepath`, not Vite's `base`. | ||
| 3. Inspect script and stylesheet URLs and confirm that they contain Vite's `base`. | ||
| 4. Load a nested route directly to verify that the production server forwards it correctly. | ||
|
|
||
| For runtime asset rewriting with a Content Delivery Network (CDN), see the [React CDN Asset URLs guide](../../react/guide/cdn-asset-urls). |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.