-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrouter.js
47 lines (39 loc) · 1.7 KB
/
router.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import { componentConfigs } from "./config/componentConfig.js";
const createComponent = async (path) => {
const response = await fetch(`../components/${path}.html`);
if (!response.ok) {
throw new Error(`Failed to fetch template for ${path}`);
}
const template = await response.text();
// Fetch the specific component configuration
let componentConfig = componentConfigs[path] || {};
// console.log(`componentConfig ${path}`, componentConfig);
// If there's no predefined setup, use a default one (or you can choose to omit this)
if (!componentConfig.setup) {
componentConfig = {
...componentConfig,
setup() {
return {}; // Return an empty object if no setup is needed
}
};
}
// console.log(`Loaded template for -> ${path}`);
// console.log(template);
// Add the loaded template to the component configuration
componentConfig.template = template;
// console.log(`componentConfig ${path} - `, componentConfig);
return componentConfig;
}
const routes = [
{ path: '/', component: () => createComponent('Home') },
{ path: '/login', component: () => createComponent('Login') },
{ path: '/registro', component: () => createComponent('Registro') },
{ path: '/dashboard', component: () => createComponent('Dash') },
{ path: '/gasto', component: () => createComponent('Gasto') },
{ path: '/contacto', component: () => createComponent('Contacto') },
{ path: '/formsuccess', component: () => createComponent('FormSuccess') },
{ path: '/404', component: () => createComponent('ErrorPage')},
{ path: '/test', component: () => createComponent('Test') },
// { path: '/:pathMatch(.*)*', component: () => createComponent('ErrorPage')}
];
export default routes;