vaderjs 1.2.4 → 1.2.5

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/vaderRouter.js +20 -7
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vaderjs",
3
- "version": "1.2.4",
3
+ "version": "1.2.5",
4
4
  "description": "A Reactive Framework for Single-Page Applications (SPA)",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/vaderRouter.js CHANGED
@@ -2,6 +2,7 @@
2
2
  /**
3
3
  * @class VaderRouter
4
4
  * @description - creates an instance of Vader Express Router
5
+ *
5
6
  * @param {String} path
6
7
  * @param {Function} handler
7
8
  * @param {object} req request object
@@ -10,11 +11,18 @@
10
11
  *
11
12
  */
12
13
  class VaderRouter{
13
- constructor() {
14
+ /**
15
+ * @constructor
16
+ * @param {*} basePath
17
+ *
18
+ */
19
+ constructor(basePath) {
14
20
  this.routes = [];
15
21
  this.middlewares = [];
16
22
  this.errorMiddlewares = [];
17
23
  this.listeners = [];
24
+
25
+ this.basePath = basePath;
18
26
  }
19
27
 
20
28
  /**
@@ -124,22 +132,27 @@ class VaderRouter{
124
132
  }
125
133
  const routePathParts = route.path.split('/');
126
134
  const hashParts = hash.split('/');
127
- // if asterisk is present in route path then it will be the last part
128
- if(routePathParts[routePathParts.length-1].startsWith('*')){
129
- return true;
130
- }else if (routePathParts.length !== hashParts.length) {
135
+ if (routePathParts.length !== hashParts.length) {
131
136
  return false;
137
+ }else if(routePathParts[routePathParts.length-1].startsWith('*')){
138
+ return true;
132
139
  }
133
-
134
140
  const params = this.extractParams( route.path, hash);
135
141
  return Object.keys(params).length > 0;
136
142
  });
137
143
 
138
144
  if (!route) {
139
145
  route = this.routes.find((route) => {
140
- return route.path === '/404';
146
+
147
+ if(route.path === '/404'){
148
+ return true;
149
+ }else{
150
+ window.location.hash = this.basePath
151
+ }
141
152
  });
142
153
 
154
+ route ? status = 200 :
155
+
143
156
  status = 404;
144
157
  }
145
158