Added routes/novigation/notfound

This commit is contained in:
2021-10-08 11:55:47 +03:00
parent 5433fe65ea
commit f5efd4b551
21 changed files with 197 additions and 55 deletions

View File

@@ -0,0 +1,55 @@
import Views from '../templates/Views'
export default class RouteController {
constructor () {
document.addEventListener('DOMContentLoaded', e => {
this._navigation()
this._history()
})
}
get routes () {
return window.env.routes
}
/**
*
* @returns {*}
*/
get navbar () {
return document.getElementById(window.env.querySelectors.navTabs.slice(1))
}
get page404(){
document.body.innerHTML = Views.templates.notFound
setTimeout( () => {
window.location.assign('/')
}, 5000)
}
/**
*
* @private
*/
_navigation(){
if( Object.keys(this.routes).filter( path => window.location.pathname === path ).length === 0 ){
this.page404
} else{
document.querySelector( `a[href='${window.location.pathname}']` ).click()
}
}
_history(){
window.addEventListener('popstate', event => {
try {
document.querySelector('.uk-active').classList.remove('uk-active')
document.querySelector(window.env.querySelectors.navTabs + ` a[href='${event.target.location.pathname}']`).closest('.nav-tab').classList.add('uk-active')
} catch (e) {}
})
}
}