Base
This commit is contained in:
26
nginx/static/scripts/router.js
Normal file
26
nginx/static/scripts/router.js
Normal file
@ -0,0 +1,26 @@
|
||||
import { displayHome, displaySources, displaySuggestionForm, displaySearchForm } from './main.js';
|
||||
|
||||
const routes = {
|
||||
'/': displayHome,
|
||||
'/sources': () => {
|
||||
// Simulons des données pour l'exemple
|
||||
const sources = [
|
||||
{ title: 'Source 1', description: 'Description 1', category: 'Médical', archiveUrl: '#' },
|
||||
{ title: 'Source 2', description: 'Description 2', category: 'Scientifique', archiveUrl: '#' },
|
||||
];
|
||||
displaySources(sources);
|
||||
},
|
||||
'/suggest': displaySuggestionForm,
|
||||
'/search': displaySearchForm
|
||||
};
|
||||
|
||||
export function initRouter() {
|
||||
async function router() {
|
||||
const path = window.location.hash.slice(1) || '/';
|
||||
const route = routes[path] || routes['/'];
|
||||
await route();
|
||||
}
|
||||
|
||||
window.addEventListener('hashchange', router);
|
||||
window.addEventListener('load', router);
|
||||
}
|
||||
Reference in New Issue
Block a user