@uniweb/runtime 1.1.19 → 1.1.20
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 +2 -2
- package/src/hooks/useLinkInterceptor.js +20 -23
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uniweb/runtime",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.20",
|
|
4
4
|
"description": "Minimal runtime for loading Uniweb foundations",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"esbuild": "^0.21.0 || ^0.23.0 || ^0.24.0 || ^0.25.0 || ^0.27.0 || ^0.28.0",
|
|
45
45
|
"vite": "^7.3.1",
|
|
46
46
|
"vitest": "^4.1.7",
|
|
47
|
-
"@uniweb/build": "1.8.
|
|
47
|
+
"@uniweb/build": "1.8.5"
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
50
50
|
"react": "^19.0.0",
|
|
@@ -80,9 +80,9 @@ function findAnchorElement(target) {
|
|
|
80
80
|
*
|
|
81
81
|
* Which locale a path names is the hosts' rule (`localeOfPath`): a served locale's prefix,
|
|
82
82
|
* else the locale served unprefixed. The page is the route that locale shows, made canonical.
|
|
83
|
-
*
|
|
83
|
+
* It reads a path only; the click handler resolves every href to one first.
|
|
84
84
|
*
|
|
85
|
-
* @param {string} routeHref -
|
|
85
|
+
* @param {string} routeHref - Where the link goes, as a path, base path removed
|
|
86
86
|
* @param {Object} website - The active Website
|
|
87
87
|
* @returns {{ locale: string, route: string } | null}
|
|
88
88
|
*/
|
|
@@ -167,48 +167,45 @@ export function useLinkInterceptor(options = {}) {
|
|
|
167
167
|
const target = anchor.getAttribute('target')
|
|
168
168
|
if (target && target !== '_self') return
|
|
169
169
|
|
|
170
|
-
// Strip basePath from href for internal processing
|
|
171
|
-
// Links from <Link reload> include the basePath, but React Router
|
|
172
|
-
// and locale detection work with router-relative paths
|
|
173
170
|
const website = globalThis.uniweb?.activeWebsite
|
|
174
171
|
const basePath = website?.basePath || ''
|
|
175
172
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
173
|
+
// Where the browser would go, as a path: the href resolved against this page's URL, so
|
|
174
|
+
// a query (`?tab=2`) or a relative href (`about`) is judged like any other path. The
|
|
175
|
+
// base path comes off, because React Router and locale detection work with
|
|
176
|
+
// router-relative paths (a <Link reload> carries the base).
|
|
177
|
+
//
|
|
178
|
+
// ⛔ Until 2026-10-24 an href that was not a path counted as the default locale's, so
|
|
179
|
+
// on any other locale's page it was a page load: a query or a relative link reloaded
|
|
180
|
+
// the page, and left an editor's preview frame.
|
|
181
|
+
const resolved = new URL(href, window.location.href)
|
|
182
|
+
let routeHref = resolved.pathname + resolved.search + resolved.hash
|
|
183
|
+
if (basePath && routeHref.startsWith(basePath)) {
|
|
184
|
+
routeHref = routeHref.slice(basePath.length) || '/'
|
|
179
185
|
}
|
|
180
186
|
|
|
181
187
|
// A link to another locale's page is a page load, since that locale is its own document,
|
|
182
188
|
// and the browser makes it. A host that switches locale its own way (`uniweb.localeSwitch`:
|
|
183
189
|
// an editor's preview, which a page load would leave) is handed it instead, a
|
|
184
190
|
// `<Link reload>` from a language menu and a plain link to `/fr/…` alike.
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
if (
|
|
191
|
+
const switchTo = localeSwitchOf(routeHref, website)
|
|
192
|
+
if (switchTo) {
|
|
193
|
+
if (globalThis.uniweb?.localeSwitch) {
|
|
188
194
|
event.preventDefault()
|
|
189
195
|
website.switchLocale(switchTo.locale, switchTo.route)
|
|
190
|
-
return
|
|
191
196
|
}
|
|
197
|
+
return
|
|
192
198
|
}
|
|
193
199
|
|
|
194
200
|
// Opt out: anchors marked for full-page reload (e.g., <Link reload>)
|
|
195
201
|
if (anchor.hasAttribute('data-reload')) return
|
|
196
202
|
|
|
197
|
-
// Check if this link switches locale (requires full page reload). Any href that is not
|
|
198
|
-
// a path counts as the default locale's, as it always has.
|
|
199
|
-
if (website?.hasMultipleLocales()) {
|
|
200
|
-
const isLocaleSwitch = routeHref.startsWith('/') && !routeHref.startsWith('//')
|
|
201
|
-
? !!localeSwitchOf(routeHref, website)
|
|
202
|
-
: website.getActiveLocale() !== website.getDefaultLocale()
|
|
203
|
-
if (isLocaleSwitch) return // Allow full page reload
|
|
204
|
-
}
|
|
205
|
-
|
|
206
203
|
// Prevent the default browser navigation
|
|
207
204
|
event.preventDefault()
|
|
208
205
|
|
|
209
206
|
// Handle hash-only links (same page scroll)
|
|
210
|
-
if (
|
|
211
|
-
const elementId =
|
|
207
|
+
if (href.startsWith('#')) {
|
|
208
|
+
const elementId = href.slice(1)
|
|
212
209
|
if (elementId) {
|
|
213
210
|
scrollToElement(elementId)
|
|
214
211
|
// Update URL hash without navigation
|