Skip to content

Commit 3024591

Browse files
authored
fix: derive router basename from base href at runtime @W-21338965@ (#154)
fix: derive router basename from <base href> at runtime Add guidance to building-ui-bundle-frontend skill to always derive the client-side router basename from the document's <base href> tag instead of hardcoding it.
1 parent edbd8bf commit 3024591

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

  • skills/building-ui-bundle-frontend

skills/building-ui-bundle-frontend/SKILL.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,15 @@ Before finishing, confirm: Did I update `appLayout.tsx` with real nav items and
4343

4444
Use a single router package. With `createBrowserRouter` / `RouterProvider`, all imports must come from `react-router` (not `react-router-dom`).
4545

46+
If the app uses a client-side router (React Router, Remix Router, Vue Router, etc.), always derive basename / basepath / base from the document's `<base href>` tag at runtime. Never hardcode the basename:
47+
48+
```js
49+
const basename = document.querySelector('base')
50+
? new URL(document.querySelector('base').href).pathname.replace(/\/$/, '')
51+
: '/';
52+
const router = createBrowserRouter(routes, { basename });
53+
```
54+
4655
### Component Library and Styling
4756

4857
- **shadcn/ui** for components: `import { Button } from '@/components/ui/button';`

0 commit comments

Comments
 (0)