Skip to content
Snippets Groups Projects
Commit 38a37ea3 authored by Matthieu Vannin's avatar Matthieu Vannin
Browse files

partie C2.2 en cours

parent e54d13d2
No related branches found
No related tags found
No related merge requests found
import { doc } from 'prettier';
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 +13,18 @@ export default class Router {
this.contentElement.innerHTML = route.page.render();
}
}
static set menuElement(element) {
this.#menuElement = element;
let value = element.querySelectorAll('a');
value.forEach(elem => {
console.log(elem);
elem.addEventListener('click', event => {
console.log('event');
});
});
// 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é
}
}
import Router from './Router';
import data from './data';
import Component from './components/Component.js';
import PizzaList from './pages/PizzaList';
import { doc } from 'prettier';
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.navigate('/'); // affiche une page vide
pizzaList.pizzas = data;
Router.navigate('/'); // affiche la liste des pizzas
document.body.children[1].setAttribute('style', '');
const link = document.querySelector('.newsContainer .closeButton');
link.addEventListener('click', event => {
document.body.children[1].setAttribute('style', 'display:none');
});
Router.menuElement = document.querySelector('.mainMenu');
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment