@uniweb/runtime 0.5.8 → 0.5.9

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniweb/runtime",
3
- "version": "0.5.8",
3
+ "version": "0.5.9",
4
4
  "description": "Minimal runtime for loading Uniweb foundations",
5
5
  "type": "module",
6
6
  "exports": {
@@ -31,7 +31,7 @@
31
31
  "node": ">=20.19"
32
32
  },
33
33
  "dependencies": {
34
- "@uniweb/core": "0.3.8"
34
+ "@uniweb/core": "0.3.9"
35
35
  },
36
36
  "devDependencies": {
37
37
  "@vitejs/plugin-react": "^4.5.2",
@@ -147,13 +147,23 @@ export function useLinkInterceptor(options = {}) {
147
147
  const target = anchor.getAttribute('target')
148
148
  if (target && target !== '_self') return
149
149
 
150
- // Check if this link switches locale (requires full page reload)
150
+ // Strip basePath from href for internal processing
151
+ // Links from <Link reload> include the basePath, but React Router
152
+ // and locale detection work with router-relative paths
151
153
  const website = globalThis.uniweb?.activeWebsite
154
+ const basePath = website?.basePath || ''
155
+
156
+ let routeHref = href
157
+ if (basePath && href.startsWith(basePath)) {
158
+ routeHref = href.slice(basePath.length) || '/'
159
+ }
160
+
161
+ // Check if this link switches locale (requires full page reload)
152
162
  if (website?.hasMultipleLocales()) {
153
163
  const activeLocale = website.getActiveLocale()
154
164
  const defaultLocale = website.getDefaultLocale()
155
165
  const localeCodes = website.getLocales().map(l => l.code)
156
- const hrefMatch = href.match(/^\/([a-z]{2,3}(?:-[A-Z]{2})?)(?:\/|$)/)
166
+ const hrefMatch = routeHref.match(/^\/([a-z]{2,3}(?:-[A-Z]{2})?)(?:\/|$)/)
157
167
  const hrefLocale = hrefMatch?.[1]
158
168
 
159
169
  let isLocaleSwitch = false
@@ -170,8 +180,8 @@ export function useLinkInterceptor(options = {}) {
170
180
  event.preventDefault()
171
181
 
172
182
  // Handle hash-only links (same page scroll)
173
- if (href.startsWith('#')) {
174
- const elementId = href.slice(1)
183
+ if (routeHref.startsWith('#')) {
184
+ const elementId = routeHref.slice(1)
175
185
  if (elementId) {
176
186
  scrollToElement(elementId)
177
187
  // Update URL hash without navigation
@@ -180,10 +190,10 @@ export function useLinkInterceptor(options = {}) {
180
190
  return
181
191
  }
182
192
 
183
- // Use React Router navigation
193
+ // Use React Router navigation (with router-relative path)
184
194
  // React Router will handle the path, and our useEffect above
185
195
  // will handle scrolling to hash after navigation completes
186
- navigate(href)
196
+ navigate(routeHref)
187
197
  }
188
198
 
189
199
  // Add click listener to document
package/src/index.jsx CHANGED
@@ -300,6 +300,11 @@ function render({ development = false, basename } = {}) {
300
300
  ? rawPath.slice(basePath.length) || '/'
301
301
  : rawPath
302
302
  website.setActivePage(routePath)
303
+
304
+ // Store base path on Website for components that need it (e.g., Link reload)
305
+ if (website.setBasePath) {
306
+ website.setBasePath(routerBasename || '')
307
+ }
303
308
  }
304
309
 
305
310
  const root = createRoot(container)