Skip to content
Snippets Groups Projects
Commit 0d1b35be authored by David Battais's avatar David Battais
Browse files

partie C2.2 en cours

parent e54d13d2
Branches master
No related tags found
No related merge requests found
...@@ -10,4 +10,12 @@ export default class Router { ...@@ -10,4 +10,12 @@ export default class Router {
this.contentElement.innerHTML = route.page.render(); this.contentElement.innerHTML = route.page.render();
} }
} }
static #menuElement;
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é
}
} }
import Router from './Router'; import Router from './Router';
import data from './data'; import data from './data';
import PizzaList from './pages/PizzaList'; import PizzaList from './pages/PizzaList';
import Component from './components/Component';
Router.titleElement = document.querySelector('.pageTitle'); Router.titleElement = document.querySelector('.pageTitle');
Router.contentElement = document.querySelector('.pageContent'); Router.contentElement = document.querySelector('.pageContent');
const pizzaList = new PizzaList([]); 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' }]; Router.routes = [{ path: '/', page: pizzaList, title: 'La carte' }];
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');
const linkB = document.querySelector('.newsContainer .closeButton');
linkB.addEventListener('click', event => {
document.body.children[1].setAttribute('style', 'display:none');
});
document.body.children[1].setAttribute('style', '');
Router.navigate('/'); // affiche une page vide Router.navigate('/'); // affiche une page vide
pizzaList.pizzas = data; pizzaList.pizzas = data;
Router.navigate('/'); // affiche la liste des pizzas Router.navigate('/'); // affiche la liste des pizzas
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment