From 06df2ff6c1e377d29016429e964fe4c53b9db266 Mon Sep 17 00:00:00 2001 From: NicolasCantu Date: Thu, 23 Oct 2025 21:13:53 +0200 Subject: [PATCH] Add debug logs to router navigation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit **Motivations :** - Application initializes but doesn't display anything after service initialization - Need to identify where navigation fails in the router flow **Modifications :** - Added debug logs to navigate() function to track path processing - Added debug logs to handleLocation() function to track route handling - Added debug logs to home route processing to track component creation - Added debug logs to navigation completion in init() function **Pages affectΓ©es :** - src/router.ts --- src/pages/home/home.ts | 4 ++-- src/router.ts | 17 ++++++++++++++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/pages/home/home.ts b/src/pages/home/home.ts index be7a485..715c57f 100755 --- a/src/pages/home/home.ts +++ b/src/pages/home/home.ts @@ -533,7 +533,7 @@ export function setupMainPairing(): void { async function handleMainPairing(): Promise { const container = getCorrectDOM('login-4nk-component') as HTMLElement; const mainStatus = container.querySelector('#main-status') as HTMLElement; - + try { // Update UI if (mainStatus) { @@ -583,7 +583,7 @@ async function handleMainPairing(): Promise { } catch (error) { console.error('Pairing failed:', error); - + if (mainStatus) { mainStatus.innerHTML = '❌ Authentication failed'; } diff --git a/src/router.ts b/src/router.ts index a7bb116..9b71e26 100755 --- a/src/router.ts +++ b/src/router.ts @@ -22,6 +22,7 @@ const routes: { [key: string]: string } = { export let currentRoute = ''; export async function navigate(path: string) { + console.log('🧭 Navigate called with path:', path); cleanSubscriptions(); cleanPage(); path = path.replace(/^\//, ''); @@ -31,30 +32,41 @@ export async function navigate(path: string) { path = 'home'; } } + console.log('🧭 Final path after processing:', path); await handleLocation(path); + console.log('🧭 handleLocation completed for path:', path); } async function handleLocation(path: string) { + console.log('πŸ“ handleLocation called with path:', path); const parsedPath = path.split('/'); if (path.includes('/')) { path = parsedPath[0]; } currentRoute = path; const routeHtml = routes[path] || routes['home']; + console.log('πŸ“ Current route set to:', currentRoute); + console.log('πŸ“ Route HTML:', routeHtml); const content = document.getElementById('containerId'); + console.log('πŸ“ Container element found:', !!content); if (content) { if (path === 'home') { + console.log('🏠 Processing home route...'); // Use LoginComponent const loginComponent = LoginComponent; const container = document.querySelector('#containerId'); + console.log('🏠 Container for home:', !!container); const accountComponent = document.createElement('login-4nk-component'); accountComponent.setAttribute( 'style', 'width: 100vw; height: 100vh; position: relative; grid-row: 2;' ); - if (container) container.appendChild(accountComponent); + if (container) { + container.appendChild(accountComponent); + console.log('🏠 Component appended to container'); + } // Initialize the home page after component is added to DOM console.log('🏠 Initializing home page...'); @@ -66,6 +78,7 @@ async function handleLocation(path: string) { console.error('❌ Failed to initialize home page:', error); } } else { + console.log('πŸ“ Processing other route:', path); const html = await fetch(routeHtml).then(data => data.text()); content.innerHTML = html; } @@ -186,9 +199,11 @@ export async function init(): Promise { if (isPaired) { console.log('βœ… Device is paired, navigating to account page...'); await navigate('account'); + console.log('βœ… Navigation to account completed'); } else { console.log('⚠️ Device not paired, navigating to home page...'); await navigate('home'); + console.log('βœ… Navigation to home completed'); } console.log('βœ… Application initialization completed successfully');