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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/runtime/router.js +10 -9
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "vaderjs",
3
3
  "description": "A Reactive library aimed to helping you build reactive applications inspired by react.js",
4
4
  "module": "vader.js",
5
- "version": "1.3.3-alpha-138",
5
+ "version": "1.3.3-alpha-139",
6
6
  "bin": {
7
7
  "vader": "./vader.js"
8
8
  },
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(!routes.find((route)=>route.url === baseRoute)){
79
- console.error(`Route ${route} not found`);
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 = this.routes.find((route) => {
149
- if (route.path === hash) {
148
+ let route = window.routes.find((route) => {
149
+ if (route.url === hash) {
150
150
  return true;
151
151
  }
152
152
 
153
- if(hash === '' && route.path === '/'){
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.path.includes('*') || route.path.includes(':')) {
161
- const routeParts = route.path.split('/').filter((part) => part !== '');
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.path.endsWith('*')) {
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
- console.log(this.routes)
206
+ window.history.pushState({}, '', '/404');
207
+ window.dispatchEvent(new Event('popstate'));
207
208
  this.error = true;
208
209
  return false
209
210