Skip to content

Commit bcf8e5b

Browse files
authored
Merge pull request #1168 from objectstack-ai/copilot/fix-routing-issue-after-studio-migration
fix(studio): honor Vite BASE_URL as TanStack Router basepath
2 parents aab3a36 + 6a52c2a commit bcf8e5b

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

apps/studio/CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
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

apps/studio/src/router.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,31 @@
1010
import { createRouter } from '@tanstack/react-router';
1111
import { 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
1640
declare module '@tanstack/react-router' {

0 commit comments

Comments
 (0)