@uniweb/runtime 0.3.1 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.jsx +16 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniweb/runtime",
3
- "version": "0.3.1",
3
+ "version": "0.4.0",
4
4
  "description": "Minimal runtime for loading Uniweb foundations",
5
5
  "type": "module",
6
6
  "exports": {
package/src/index.jsx CHANGED
@@ -152,6 +152,18 @@ function initUniweb(configData) {
152
152
  return uniwebInstance
153
153
  }
154
154
 
155
+ /**
156
+ * Get the router basename from Vite's BASE_URL
157
+ * Vite sets this based on the `base` config option
158
+ * Returns undefined for root path ('/'), otherwise strips trailing slash
159
+ */
160
+ function getBasename() {
161
+ const baseUrl = import.meta.env?.BASE_URL
162
+ if (!baseUrl || baseUrl === '/') return undefined
163
+ // Remove trailing slash for BrowserRouter compatibility
164
+ return baseUrl.endsWith('/') ? baseUrl.slice(0, -1) : baseUrl
165
+ }
166
+
155
167
  /**
156
168
  * Render the application
157
169
  * @param {Object} options
@@ -163,6 +175,9 @@ function render({ development = false, basename } = {}) {
163
175
  return
164
176
  }
165
177
 
178
+ // Use provided basename, or derive from Vite's BASE_URL
179
+ const routerBasename = basename ?? getBasename()
180
+
166
181
  const root = createRoot(container)
167
182
 
168
183
  const app = (
@@ -174,7 +189,7 @@ function render({ development = false, basename } = {}) {
174
189
  </div>
175
190
  }
176
191
  >
177
- <BrowserRouter basename={basename}>
192
+ <BrowserRouter basename={routerBasename}>
178
193
  <Routes>
179
194
  <Route path="/*" element={<WebsiteRenderer />} />
180
195
  </Routes>