Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possibility to add optional parameters #186

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions app-route.html
Original file line number Diff line number Diff line change
Expand Up @@ -253,17 +253,12 @@
if (!this.route) {
return;
}
var path = this.route.path;
var path = this.route.path || "";
var pattern = this.pattern;
if (!pattern) {
return;
}

if (!path) {
this.__resetProperties();
return;
}

var remainingPieces = path.split('/');
var patternPieces = pattern.split('/');

Expand All @@ -276,17 +271,25 @@
break;
}
var pathPiece = remainingPieces.shift();

// We don't match this path.
if (!pathPiece && pathPiece !== '') {
var patternPieceOptional = false;

if (patternPiece.slice(-1) == '?') {
// Optional parameter.
patternPiece = patternPiece.slice(0, -1);
patternPieceOptional = true;
} else if (!pathPiece && pathPiece !== '') {
// No optional parameter and we don't match this path.
this.__resetProperties();
return;
}
matched.push(pathPiece);

if (pathPiece !== undefined) {
matched.push(pathPiece);
}

if (patternPiece.charAt(0) == ':') {
namedMatches[patternPiece.slice(1)] = pathPiece;
} else if (patternPiece !== pathPiece) {
} else if (patternPiece !== pathPiece && !patternPieceOptional) {
this.__resetProperties();
return;
}
Expand Down