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 { getAvailablePages, getPageByRoute } from './pages/pagesRegistry.js';
|
||||
|
||||
// 🔧 Modo DEV: cambiar a false para activar login
|
||||
const DEV_MODE = false;
|
||||
|
||||
export function initRouter() {
|
||||
const app = document.querySelector('#app');
|
||||
|
||||
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
|
||||
|
||||
if (!auth.checkAuth() && hash !== '#login') {
|
||||
if (!DEV_MODE && !auth.checkAuth() && hash !== '#login') {
|
||||
window.location.hash = '#login';
|
||||
return;
|
||||
}
|
||||
|
|
@ -18,7 +21,8 @@ export function initRouter() {
|
|||
app.innerHTML = '';
|
||||
|
||||
// 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');
|
||||
layout.className = 'app-layout';
|
||||
|
||||
|
|
@ -39,7 +43,7 @@ export function initRouter() {
|
|||
return;
|
||||
}
|
||||
|
||||
if (page.requiresAuth && !auth.checkAuth()) {
|
||||
if (!DEV_MODE && page.requiresAuth && !auth.checkAuth()) {
|
||||
window.location.hash = '#login';
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue