File tree Expand file tree Collapse file tree 2 files changed +37
-1
lines changed
Expand file tree Collapse file tree 2 files changed +37
-1
lines changed Original file line number Diff line number Diff line change 11# @objectstack/studio
22
3+ ## Unreleased
4+
5+ ### Patch Changes
6+
7+ - Fix TanStack Router basepath resolution when Studio is mounted under a sub-path
8+ (e.g. ` /_studio/ ` via the CLI ` --ui ` flag). Previously, routes such as
9+ ` /_studio/packages ` or ` /_studio/:package/objects/:name ` failed to match —
10+ the router treated the mount prefix as a ` $package ` route parameter, producing
11+ "Not Found" errors. The router now derives ` basepath ` from Vite's
12+ ` import.meta.env.BASE_URL ` , which works transparently for both root and
13+ sub-path deployments.
14+
315## 4.0.4
416
517### Patch Changes
Original file line number Diff line number Diff line change 1010import { createRouter } from '@tanstack/react-router' ;
1111import { routeTree } from './routeTree.gen' ;
1212
13- export const router = createRouter ( { routeTree } ) ;
13+ /**
14+ * Compute the router basepath from Vite's `BASE_URL`.
15+ *
16+ * When Studio is mounted under a sub-path (e.g. `/_studio/` via the CLI `--ui`
17+ * flag, which sets `VITE_BASE=/_studio/`), TanStack Router must strip that
18+ * prefix before matching route patterns. Otherwise URLs such as
19+ * `/_studio/packages` are mis-interpreted as `/$package="_studio"/packages`.
20+ *
21+ * Vite exposes the configured base as `import.meta.env.BASE_URL`:
22+ * - Root deployment: `'/'` → basepath `'/'` (no-op)
23+ * - Sub-path deployment: `'/_studio/'` → basepath `'/_studio'`
24+ *
25+ * TanStack Router expects the basepath WITHOUT a trailing slash (except for
26+ * the root `'/'`), so we normalise accordingly.
27+ */
28+ function resolveBasepath ( ) : string {
29+ const base = ( import . meta. env . BASE_URL ?? '/' ) . trim ( ) ;
30+ if ( ! base || base === '/' || base === './' ) return '/' ;
31+ return base . endsWith ( '/' ) ? base . slice ( 0 , - 1 ) : base ;
32+ }
33+
34+ export const router = createRouter ( {
35+ routeTree,
36+ basepath : resolveBasepath ( ) ,
37+ } ) ;
1438
1539// Register things for type-safety
1640declare module '@tanstack/react-router' {
You can’t perform that action at this time.
0 commit comments