Skip to content

Commit 0f4cd38

Browse files
authored
[DerivedSubpath] fix issue with complex routes (#23)
1 parent 9065470 commit 0f4cd38

File tree

6 files changed

+13
-6
lines changed

6 files changed

+13
-6
lines changed

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "dragon-router",
3-
"version": "1.1.2",
3+
"version": "1.2.0",
44
"description": "An ExpressJS-like client side router built from the ground up on debuggability and simplicity",
55
"authors": [
66
"Kyle West <kyle-west@github.com>"

dist/dragon-router.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,10 @@ class Router {
191191
use (firstArg, ...actions) {
192192
if (firstArg instanceof DerivedSubpath) {
193193
this.subPaths[firstArg.name] = firstArg.callback;
194+
if (actions.length > 0) { this.use(...actions) }
194195
} else if (firstArg instanceof RouteHandler) {
195196
this._registerHandlers(firstArg);
197+
if (actions.length > 0) { this.use(...actions) }
196198
} else if (firstArg instanceof Function) { // middleware
197199
this.globalActions = [...this.globalActions, firstArg, ...actions];
198200
} else if (firstArg instanceof Array) {
@@ -262,7 +264,7 @@ class Router {
262264
let matcher = s.match(/[$]?:/)
263265
if (matcher) {
264266
let sectionName = s.replace(matcher[0], '').split('(')[0];
265-
if (matcher[0].startsWith('$')) {
267+
if (matcher[0].startsWith('$') && !context.params[sectionName]) {
266268
return this.subPaths[sectionName](context)
267269
} else {
268270
return context.params[sectionName] || s
@@ -407,6 +409,7 @@ class Router {
407409
return this;
408410
}
409411
}
412+
410413
if (typeof module === 'object' && module.exports) {
411414
module.exports = {Router, Context, DerivedSubpath, RouteHandler, TokenizedPath}
412415
} else {

dist/dragon-router.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/dragon-router.module.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,10 @@ export class Router {
191191
use (firstArg, ...actions) {
192192
if (firstArg instanceof DerivedSubpath) {
193193
this.subPaths[firstArg.name] = firstArg.callback;
194+
if (actions.length > 0) { this.use(...actions) }
194195
} else if (firstArg instanceof RouteHandler) {
195196
this._registerHandlers(firstArg);
197+
if (actions.length > 0) { this.use(...actions) }
196198
} else if (firstArg instanceof Function) { // middleware
197199
this.globalActions = [...this.globalActions, firstArg, ...actions];
198200
} else if (firstArg instanceof Array) {
@@ -262,7 +264,7 @@ export class Router {
262264
let matcher = s.match(/[$]?:/)
263265
if (matcher) {
264266
let sectionName = s.replace(matcher[0], '').split('(')[0];
265-
if (matcher[0].startsWith('$')) {
267+
if (matcher[0].startsWith('$') && !context.params[sectionName]) {
266268
return this.subPaths[sectionName](context)
267269
} else {
268270
return context.params[sectionName] || s

dragon-router.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,10 @@ export class Router {
191191
use (firstArg, ...actions) {
192192
if (firstArg instanceof DerivedSubpath) {
193193
this.subPaths[firstArg.name] = firstArg.callback;
194+
if (actions.length > 0) { this.use(...actions) }
194195
} else if (firstArg instanceof RouteHandler) {
195196
this._registerHandlers(firstArg);
197+
if (actions.length > 0) { this.use(...actions) }
196198
} else if (firstArg instanceof Function) { // middleware
197199
this.globalActions = [...this.globalActions, firstArg, ...actions];
198200
} else if (firstArg instanceof Array) {
@@ -262,7 +264,7 @@ export class Router {
262264
let matcher = s.match(/[$]?:/)
263265
if (matcher) {
264266
let sectionName = s.replace(matcher[0], '').split('(')[0];
265-
if (matcher[0].startsWith('$')) {
267+
if (matcher[0].startsWith('$') && !context.params[sectionName]) {
266268
return this.subPaths[sectionName](context)
267269
} else {
268270
return context.params[sectionName] || s

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "dragon-router",
3-
"version": "1.1.2",
3+
"version": "1.2.0",
44
"description": "An ExpressJS-like client side router built from the ground up on debuggability and simplicity",
55
"author": {
66
"name": "Kyle West",

0 commit comments

Comments
 (0)