|
1 | 1 | /** |
2 | 2 | * Router module for SPA navigation |
3 | 3 | */ |
4 | | -import { Router, transitions, renderer, componentLoader, enhancedRouter } from './deps.js'; |
| 4 | +import { Router, transitions, renderer, componentLoader } from './deps.js'; |
5 | 5 | import { localizer } from './i18n-setup.js'; |
6 | 6 | import { |
7 | 7 | initLoginPage, |
@@ -215,103 +215,73 @@ export function createRouter(options = {}) { |
215 | 215 | } |
216 | 216 | }); |
217 | 217 |
|
218 | | - // Create the router using enhancedRouter with fallback to basic router |
219 | | - let router; |
| 218 | + // Create a basic router |
| 219 | + console.log('Creating basic router'); |
| 220 | + const router = new Router({ |
| 221 | + rootElement: options.rootElement || '#app', |
| 222 | + transition: customFade, |
| 223 | + renderer: renderer.createRenderer({ |
| 224 | + translateContainer: localizer.translateContainer.bind(localizer), |
| 225 | + applyRTLToDocument: localizer.applyRTLToDocument.bind(localizer), |
| 226 | + keepScripts: true // Keep script tags in views |
| 227 | + }) |
| 228 | + }); |
220 | 229 |
|
221 | | - try { |
222 | | - // Check if enhancedRouter is properly initialized |
223 | | - if (enhancedRouter && typeof enhancedRouter.createEnhancedRouter === 'function') { |
224 | | - console.log('Using enhanced router'); |
225 | | - router = enhancedRouter.createEnhancedRouter({ |
226 | | - rootElement: options.rootElement || '#app', |
227 | | - transition: customFade, |
228 | | - renderer: renderer.createRenderer({ |
229 | | - translateContainer: localizer.translateContainer.bind(localizer), |
230 | | - applyRTLToDocument: localizer.applyRTLToDocument.bind(localizer), |
231 | | - keepScripts: true // Keep script tags in views |
232 | | - }), |
233 | | - i18n: localizer, // Pass the localizer to the enhanced router |
234 | | - errorHandler: (path) => { |
235 | | - console.log('Custom error handler called for path:', path); |
236 | | - |
237 | | - // Clean up any overlays immediately |
238 | | - cleanupOverlays(); |
239 | | - |
240 | | - // Set up a safety interval to periodically check for and remove any overlays |
241 | | - const safetyInterval = setInterval(cleanupOverlays, 500); |
242 | | - |
243 | | - // Clear the safety interval after 3 seconds |
244 | | - setTimeout(() => { |
245 | | - clearInterval(safetyInterval); |
246 | | - console.log('Safety interval cleared'); |
247 | | - }, 3000); |
248 | | - |
249 | | - // Create error content fragment |
250 | | - const contentFragment = document.createDocumentFragment(); |
251 | | - |
252 | | - // Create content container |
253 | | - const contentContainer = document.createElement('div'); |
254 | | - contentContainer.className = 'content-container'; |
255 | | - contentContainer.style.display = 'flex'; |
256 | | - contentContainer.style.justifyContent = 'center'; |
257 | | - contentContainer.style.alignItems = 'center'; |
258 | | - contentContainer.style.minHeight = '60vh'; |
259 | | - |
260 | | - // Create error page div |
261 | | - const errorPage = document.createElement('div'); |
262 | | - errorPage.className = 'error-page'; |
263 | | - |
264 | | - // Create heading |
265 | | - const heading = document.createElement('h1'); |
266 | | - heading.textContent = '404 - Page Not Found'; |
267 | | - errorPage.appendChild(heading); |
268 | | - |
269 | | - // Create message |
270 | | - const message = document.createElement('p'); |
271 | | - message.textContent = `The page "${path}" could not be found.`; |
272 | | - errorPage.appendChild(message); |
273 | | - |
274 | | - // Create back link |
275 | | - const backLink = document.createElement('a'); |
276 | | - backLink.href = '/'; |
277 | | - backLink.className = 'back-link'; |
278 | | - backLink.textContent = 'Go back to home'; |
279 | | - errorPage.appendChild(backLink); |
280 | | - |
281 | | - // Assemble the fragment |
282 | | - contentContainer.appendChild(errorPage); |
283 | | - contentFragment.appendChild(contentContainer); |
284 | | - |
285 | | - // Return the error wrapped in the default layout |
286 | | - return createLayoutFragment(contentFragment); |
287 | | - } |
288 | | - }); |
289 | | - } else { |
290 | | - throw new Error('Enhanced router not available or createEnhancedRouter is not a function'); |
291 | | - } |
292 | | - } catch (error) { |
293 | | - console.error('Error creating enhanced router:', error); |
| 230 | + // Add custom error handling |
| 231 | + router.errorHandler = (path) => { |
| 232 | + console.log('Custom error handler called for path:', path); |
294 | 233 |
|
295 | | - // Create a basic router with minimal functionality |
296 | | - router = { |
297 | | - rootElement: options.rootElement || '#app', |
298 | | - routes: {}, |
299 | | - registerRoutes(routes) { |
300 | | - this.routes = routes; |
301 | | - console.log('Routes registered with fallback router'); |
302 | | - }, |
303 | | - navigate(path) { |
304 | | - console.log(`Navigating to ${path} with fallback router`); |
305 | | - return Promise.resolve(); |
306 | | - }, |
307 | | - init() { |
308 | | - console.log('Fallback router initialized'); |
309 | | - }, |
310 | | - use(middleware) { |
311 | | - console.log('Middleware added to fallback router'); |
312 | | - } |
313 | | - }; |
314 | | - } |
| 234 | + // Clean up any overlays immediately |
| 235 | + cleanupOverlays(); |
| 236 | + |
| 237 | + // Set up a safety interval to periodically check for and remove any overlays |
| 238 | + const safetyInterval = setInterval(cleanupOverlays, 500); |
| 239 | + |
| 240 | + // Clear the safety interval after 3 seconds |
| 241 | + setTimeout(() => { |
| 242 | + clearInterval(safetyInterval); |
| 243 | + console.log('Safety interval cleared'); |
| 244 | + }, 3000); |
| 245 | + |
| 246 | + // Create error content fragment |
| 247 | + const contentFragment = document.createDocumentFragment(); |
| 248 | + |
| 249 | + // Create content container |
| 250 | + const contentContainer = document.createElement('div'); |
| 251 | + contentContainer.className = 'content-container'; |
| 252 | + contentContainer.style.display = 'flex'; |
| 253 | + contentContainer.style.justifyContent = 'center'; |
| 254 | + contentContainer.style.alignItems = 'center'; |
| 255 | + contentContainer.style.minHeight = '60vh'; |
| 256 | + |
| 257 | + // Create error page div |
| 258 | + const errorPage = document.createElement('div'); |
| 259 | + errorPage.className = 'error-page'; |
| 260 | + |
| 261 | + // Create heading |
| 262 | + const heading = document.createElement('h1'); |
| 263 | + heading.textContent = '404 - Page Not Found'; |
| 264 | + errorPage.appendChild(heading); |
| 265 | + |
| 266 | + // Create message |
| 267 | + const message = document.createElement('p'); |
| 268 | + message.textContent = `The page "${path}" could not be found.`; |
| 269 | + errorPage.appendChild(message); |
| 270 | + |
| 271 | + // Create back link |
| 272 | + const backLink = document.createElement('a'); |
| 273 | + backLink.href = '/'; |
| 274 | + backLink.className = 'back-link'; |
| 275 | + backLink.textContent = 'Go back to home'; |
| 276 | + errorPage.appendChild(backLink); |
| 277 | + |
| 278 | + // Assemble the fragment |
| 279 | + contentContainer.appendChild(errorPage); |
| 280 | + contentFragment.appendChild(contentContainer); |
| 281 | + |
| 282 | + // Return the error wrapped in the default layout |
| 283 | + return createLayoutFragment(contentFragment); |
| 284 | + }; |
315 | 285 |
|
316 | 286 | // Store the original init method |
317 | 287 | const originalInit = router.init; |
|
0 commit comments