26 lines
874 B
JavaScript
26 lines
874 B
JavaScript
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);
|
|
} |