vaderjs 1.3.3-alpha-138 → 1.3.3-alpha-139
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/runtime/router.js +10 -9
package/package.json
CHANGED
package/runtime/router.js
CHANGED
|
@@ -75,8 +75,8 @@ class VaderRouter{
|
|
|
75
75
|
window.onpopstate = async (e) => {
|
|
76
76
|
let route = window.location.pathname
|
|
77
77
|
let baseRoute = `/${route.split('/')[1]}`
|
|
78
|
-
if(!
|
|
79
|
-
|
|
78
|
+
if(!this.checkroute(route) && !window.devMode){
|
|
79
|
+
route = '/404'
|
|
80
80
|
}
|
|
81
81
|
let html = new DOMParser().parseFromString(await fetch(baseRoute, {
|
|
82
82
|
cache: 'reload'
|
|
@@ -145,22 +145,22 @@ class VaderRouter{
|
|
|
145
145
|
}
|
|
146
146
|
|
|
147
147
|
checkroute(hash){
|
|
148
|
-
let route =
|
|
149
|
-
if (route.
|
|
148
|
+
let route = window.routes.find((route) => {
|
|
149
|
+
if (route.url === hash) {
|
|
150
150
|
return true;
|
|
151
151
|
}
|
|
152
152
|
|
|
153
|
-
if(hash === '' && route.
|
|
153
|
+
if(hash === '' && route.url === '/'){
|
|
154
154
|
return true
|
|
155
155
|
}
|
|
156
156
|
|
|
157
157
|
if(hash.includes('?')){
|
|
158
158
|
hash = hash.split('?')[0]
|
|
159
159
|
}
|
|
160
|
-
if (route.
|
|
161
|
-
const routeParts = route.
|
|
160
|
+
if (route.url.includes('*') || route.url.includes(':')) {
|
|
161
|
+
const routeParts = route.url.split('/').filter((part) => part !== '');
|
|
162
162
|
const hashParts = hash.split('/').filter((part) => part !== '');
|
|
163
|
-
if (routeParts.length !== hashParts.length && !route.
|
|
163
|
+
if (routeParts.length !== hashParts.length && !route.url.endsWith('*')) {
|
|
164
164
|
return false;
|
|
165
165
|
}
|
|
166
166
|
|
|
@@ -203,7 +203,8 @@ class VaderRouter{
|
|
|
203
203
|
if (!route) {
|
|
204
204
|
route = window.routes.find((errorRoute) => {
|
|
205
205
|
if (errorRoute.url.includes('/404') && !this.error && !window.devMode) {
|
|
206
|
-
|
|
206
|
+
window.history.pushState({}, '', '/404');
|
|
207
|
+
window.dispatchEvent(new Event('popstate'));
|
|
207
208
|
this.error = true;
|
|
208
209
|
return false
|
|
209
210
|
|