Enhance router logic to support DEV_MODE for easier testing and navigation
This commit is contained in:
parent
63d4b8bdb4
commit
6021b351a3
|
|
@ -3,14 +3,17 @@ import { renderLoginPage } from './pages/LoginPage.js';
|
||||||
import { createSidebar } from './components/Sidebar.js';
|
import { createSidebar } from './components/Sidebar.js';
|
||||||
import { getAvailablePages, getPageByRoute } from './pages/pagesRegistry.js';
|
import { getAvailablePages, getPageByRoute } from './pages/pagesRegistry.js';
|
||||||
|
|
||||||
|
// 🔧 Modo DEV: cambiar a false para activar login
|
||||||
|
const DEV_MODE = false;
|
||||||
|
|
||||||
export function initRouter() {
|
export function initRouter() {
|
||||||
const app = document.querySelector('#app');
|
const app = document.querySelector('#app');
|
||||||
|
|
||||||
function navigate() {
|
function navigate() {
|
||||||
const hash = window.location.hash || '#login';
|
const hash = window.location.hash || (DEV_MODE ? '#dashboard' : '#login');
|
||||||
const route = hash.substring(1); // Remove the # symbol
|
const route = hash.substring(1); // Remove the # symbol
|
||||||
|
|
||||||
if (!auth.checkAuth() && hash !== '#login') {
|
if (!DEV_MODE && !auth.checkAuth() && hash !== '#login') {
|
||||||
window.location.hash = '#login';
|
window.location.hash = '#login';
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -18,7 +21,8 @@ export function initRouter() {
|
||||||
app.innerHTML = '';
|
app.innerHTML = '';
|
||||||
|
|
||||||
// For authenticated routes, add sidebar and main content wrapper
|
// For authenticated routes, add sidebar and main content wrapper
|
||||||
if (auth.checkAuth() && hash !== '#login') {
|
const isAuthenticated = DEV_MODE || auth.checkAuth();
|
||||||
|
if (isAuthenticated && hash !== '#login') {
|
||||||
const layout = document.createElement('div');
|
const layout = document.createElement('div');
|
||||||
layout.className = 'app-layout';
|
layout.className = 'app-layout';
|
||||||
|
|
||||||
|
|
@ -39,7 +43,7 @@ export function initRouter() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (page.requiresAuth && !auth.checkAuth()) {
|
if (!DEV_MODE && page.requiresAuth && !auth.checkAuth()) {
|
||||||
window.location.hash = '#login';
|
window.location.hash = '#login';
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue