Skip to content
Snippets Groups Projects
Commit edbd0af3 authored by Clotaire Dufresne's avatar Clotaire Dufresne
Browse files

c fini (retard car incompréhension)

parent f98a536c
No related branches found
No related tags found
No related merge requests found
......@@ -6,7 +6,7 @@
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "webpack --mode=production",
"watch": "webpack --mode=development --watch"
"watch": "webpack --mode=development --watch"
},
"author": "Thomas Fritsch <thomas.fritsch@univ-lille.fr> (https://gitlab.univ-lille.fr/thomas.fritsch)",
"homepage": "https://gitlab.univ-lille.fr/js",
......
......@@ -2,6 +2,7 @@ export default class Router {
static titleElement;
static contentElement;
static routes = [];
static #menuElement;
static navigate(path) {
const route = this.routes.find(route => route.path === path);
......@@ -10,4 +11,16 @@ export default class Router {
this.contentElement.innerHTML = route.page.render();
}
}
static set menuElement(element) {
this.#menuElement = element;
// au clic sur n'importe quel lien contenu dans "element"
// déclenchez un appel à Router.navigate(path)
// où "path" est la valeur de l'attribut `href=".."` du lien cliqué
element.addEventListener('click', event => {
event.preventDefault();
const target = event.target;
Router.navigate(target.getAttribute('href'));
});
}
}
import Router from './Router';
import data from './data';
import PizzaList from './pages/PizzaList';
import Component from './components/Component';
Router.titleElement = document.querySelector('.pageTitle');
Router.contentElement = document.querySelector('.pageContent');
const pizzaList = new PizzaList([]);
Router.routes = [{ path: '/', page: pizzaList, title: 'La carte' }];
const pizzaList = new PizzaList([]),
aboutPage = new Component('section', null, 'Ce site est génial'),
pizzaForm = new Component(
'section',
null,
'Ici vous pourrez ajouter une pizza'
);
Router.routes = [
{ path: '/', page: pizzaList, title: 'La carte' },
{ path: '/a-propos', page: aboutPage, title: 'À propos' },
{ path: '/ajouter-pizza', page: pizzaForm, title: 'Ajouter une pizza' },
];
Router.menuElement = document.querySelector('.mainMenu');
Router.navigate('/'); // affiche une page vide
pizzaList.pizzas = data;
Router.navigate('/'); // affiche la liste des pizzas
document.querySelector('.newsContainer').setAttribute('style', '');
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment