Skip to content

Commit

Permalink
Update router
Browse files Browse the repository at this point in the history
  • Loading branch information
rayc2045 committed Apr 28, 2024
1 parent 532e051 commit f29cbc7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 16 deletions.
4 changes: 2 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<script src="https://cdn.jsdelivr.net/npm/gsap@3.12.5/dist/gsap.min.js" defer></script>
</head>
<body
x-data="{ BRAND_NAME, prefer, localStore, ...style, ...utils, sideMenu, router, loader, shop, cart, user }"
x-data="{ BRAND_NAME, prefer, localStore, ...style, ...utils, sideMenu, router, shop, cart, user }"
class="min-h-svh flex flex-col tracking-wide bg-gray-100"
:class="sideMenu.isOpen && 'overflow-hidden'"
@dragstart.prevent
Expand Down Expand Up @@ -351,7 +351,7 @@
<main
class="flex-1"
x-init="await router.init()"
@hashchange.window="sideMenu.close(); loader.start(); await scrollToTop(); router.renderPage(); loader.end()"
@hashchange.window="sideMenu.close(); await scrollToTop(); router.updatePath(); router.renderPage();"
>
<div class="max-w-screen-xl mx-auto px-4 py-12">
<h1
Expand Down
17 changes: 3 additions & 14 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,11 @@ const sideMenu = {
const router = {
routes: [
{ path: '/', component: '/home.html' },
{ path: '/blog', component: '/blog/index.html', title: 'Recent from blog' },
{ path: '/about', component: '/about/index.html', title: 'About Us' },
{ path: '/blog', component: '/blog/posts.html', title: 'Recent from blog' },
{ path: '/about', component: '/about/about.html', title: 'About Us' },
{ path: '/contact', component: '/about/contact.html', title: 'Contact Us' },
{ path: '/faq', component: '/about/faq.html', title: 'Frequently asked questions' },
{ path: '/shop', component: '/shop/index.html', title: 'Shop' },
{ path: '/shop', component: '/shop/products.html', title: 'Shop' },
{ path: '/cart', component: '/shop/cart.html', title: 'Cart' },
{ path: '/account', component: '/account.html', title: 'My account' },
{ path: '/order-tracking', component: '/account/order-tracking.html', title: 'Order Tracking' },
Expand All @@ -185,24 +185,13 @@ const router = {
this.currentPath = path.startsWith('/') ? path : '/';
},
renderPage() {
this.updatePath();
document.title = this.currentRoute.title
? `${this.currentRoute.title} - ${BRAND_NAME}`
: BRAND_NAME;
utils.select('#router-view').innerHTML = this.currentRoute.html;
},
};

const loader = {
isLoading: true,
start() {
this.isLoading = true;
},
end() {
this.isLoading = false;
},
};

const shop = {
products: [
// { name, category, href, image, description, price }
Expand Down

0 comments on commit f29cbc7

Please sign in to comment.