@uniweb/runtime 0.5.6 → 0.5.8
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/components/PageRenderer.jsx +14 -3
- package/src/hooks/useLinkInterceptor.js +19 -0
- package/src/index.jsx +11 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uniweb/runtime",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.8",
|
|
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.
|
|
34
|
+
"@uniweb/core": "0.3.8"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@vitejs/plugin-react": "^4.5.2",
|
|
@@ -60,10 +60,10 @@ export default function PageRenderer() {
|
|
|
60
60
|
// This ensures correct page renders immediately on client-side navigation
|
|
61
61
|
let page = website?.getPage(location.pathname)
|
|
62
62
|
|
|
63
|
-
// If no page found, try the 404 page
|
|
63
|
+
// If no page found, try the 404 page (do NOT fall back to activePage/homepage)
|
|
64
64
|
const isNotFound = !page
|
|
65
65
|
if (isNotFound) {
|
|
66
|
-
page = website?.getNotFoundPage?.() ||
|
|
66
|
+
page = website?.getNotFoundPage?.() || null
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
// Get head metadata from page (uses Page.getHeadMeta() if available)
|
|
@@ -76,12 +76,23 @@ export default function PageRenderer() {
|
|
|
76
76
|
useHeadMeta(headMeta, { siteName })
|
|
77
77
|
|
|
78
78
|
if (!page) {
|
|
79
|
-
// No page and no 404 page defined - show minimal fallback
|
|
79
|
+
// No page and no 404 page defined - show minimal fallback with debug info
|
|
80
|
+
const requestedPath = location.pathname
|
|
81
|
+
const isDev = import.meta.env?.DEV
|
|
80
82
|
return (
|
|
81
83
|
<div className="page-not-found" style={{ padding: '4rem 2rem', textAlign: 'center' }}>
|
|
82
84
|
<h1 style={{ fontSize: '3rem', fontWeight: 'bold', color: '#1f2937', marginBottom: '1rem' }}>404</h1>
|
|
83
85
|
<p style={{ color: '#64748b', marginBottom: '2rem' }}>Page not found</p>
|
|
84
86
|
<a href="/" style={{ color: '#3b82f6', textDecoration: 'underline' }}>Go to homepage</a>
|
|
87
|
+
{isDev && (
|
|
88
|
+
<div style={{ marginTop: '2rem', padding: '1rem', background: '#f1f5f9', borderRadius: '0.5rem', textAlign: 'left', maxWidth: '32rem', margin: '2rem auto 0' }}>
|
|
89
|
+
<p style={{ fontWeight: '600', color: '#475569', marginBottom: '0.5rem' }}>Debug info</p>
|
|
90
|
+
<p style={{ fontSize: '0.875rem', color: '#64748b' }}>Path: {requestedPath}</p>
|
|
91
|
+
<p style={{ fontSize: '0.875rem', color: '#64748b' }}>Locale: {website?.getActiveLocale?.() || 'unknown'}</p>
|
|
92
|
+
<p style={{ fontSize: '0.875rem', color: '#64748b' }}>Known routes: {website?.pageRoutes?.join(', ') || 'none'}</p>
|
|
93
|
+
<p style={{ fontSize: '0.75rem', color: '#94a3b8', marginTop: '0.5rem' }}>Tip: Create a pages/404/ folder with a page.yml and content to customize this page.</p>
|
|
94
|
+
</div>
|
|
95
|
+
)}
|
|
85
96
|
</div>
|
|
86
97
|
)
|
|
87
98
|
}
|
|
@@ -147,6 +147,25 @@ 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)
|
|
151
|
+
const website = globalThis.uniweb?.activeWebsite
|
|
152
|
+
if (website?.hasMultipleLocales()) {
|
|
153
|
+
const activeLocale = website.getActiveLocale()
|
|
154
|
+
const defaultLocale = website.getDefaultLocale()
|
|
155
|
+
const localeCodes = website.getLocales().map(l => l.code)
|
|
156
|
+
const hrefMatch = href.match(/^\/([a-z]{2,3}(?:-[A-Z]{2})?)(?:\/|$)/)
|
|
157
|
+
const hrefLocale = hrefMatch?.[1]
|
|
158
|
+
|
|
159
|
+
let isLocaleSwitch = false
|
|
160
|
+
if (hrefLocale && localeCodes.includes(hrefLocale)) {
|
|
161
|
+
isLocaleSwitch = hrefLocale !== activeLocale
|
|
162
|
+
} else {
|
|
163
|
+
// No locale prefix = targets default locale
|
|
164
|
+
isLocaleSwitch = activeLocale !== defaultLocale
|
|
165
|
+
}
|
|
166
|
+
if (isLocaleSwitch) return // Allow full page reload
|
|
167
|
+
}
|
|
168
|
+
|
|
150
169
|
// Prevent the default browser navigation
|
|
151
170
|
event.preventDefault()
|
|
152
171
|
|
package/src/index.jsx
CHANGED
|
@@ -291,6 +291,17 @@ function render({ development = false, basename } = {}) {
|
|
|
291
291
|
// Use provided basename, or derive from Vite's BASE_URL
|
|
292
292
|
const routerBasename = basename ?? getBasename()
|
|
293
293
|
|
|
294
|
+
// Set initial active page from browser URL so getLocaleUrl() works on first render
|
|
295
|
+
const website = globalThis.uniweb?.activeWebsite
|
|
296
|
+
if (website && typeof window !== 'undefined') {
|
|
297
|
+
const rawPath = window.location.pathname
|
|
298
|
+
const basePath = routerBasename || ''
|
|
299
|
+
const routePath = basePath && rawPath.startsWith(basePath)
|
|
300
|
+
? rawPath.slice(basePath.length) || '/'
|
|
301
|
+
: rawPath
|
|
302
|
+
website.setActivePage(routePath)
|
|
303
|
+
}
|
|
304
|
+
|
|
294
305
|
const root = createRoot(container)
|
|
295
306
|
|
|
296
307
|
const app = (
|