From 073929341e4504cc9ddcc9720c24b2eb23b5ae9a Mon Sep 17 00:00:00 2001 From: Jose Ramos Date: Thu, 16 Mar 2017 14:45:36 +0100 Subject: [PATCH 1/3] posibility to add optional parameters in the pattern attribute with ? at the end --- app-route.html | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/app-route.html b/app-route.html index 7ed66b4..4c85862 100644 --- a/app-route.html +++ b/app-route.html @@ -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('/'); @@ -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; } From 45c2df488cea43984beaf4b027bdf29b62880e39 Mon Sep 17 00:00:00 2001 From: Jose Ramos Date: Thu, 16 Mar 2017 18:52:55 +0100 Subject: [PATCH 2/3] tests uploaded --- bower.json | 2 +- test/app-route-optional-params.html | 214 ++++++++++++++++++++++++++++ test/index.html | 2 +- 3 files changed, 216 insertions(+), 2 deletions(-) create mode 100644 test/app-route-optional-params.html diff --git a/bower.json b/bower.json index c90ddc7..65d8f75 100644 --- a/bower.json +++ b/bower.json @@ -17,7 +17,7 @@ "devDependencies": { "paper-styles": "polymerelements/paper-styles#^1.0.13", "paper-input": "polymerelements/paper-input#^1.1.2", - "web-component-tester": "^4.0.0", + "web-component-tester": "^5.0.1", "iron-component-page": "polymerelements/iron-component-page#^1.0.0", "iron-test-helpers": "polymerelements/iron-test-helpers#^1.0.0", "iron-pages": "PolymerElements/iron-pages#^1.0.7", diff --git a/test/app-route-optional-params.html b/test/app-route-optional-params.html new file mode 100644 index 0000000..1348dbd --- /dev/null +++ b/test/app-route-optional-params.html @@ -0,0 +1,214 @@ + + + + + app-route-optional-params + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/test/index.html b/test/index.html index f82b1f3..1a1ba82 100644 --- a/test/index.html +++ b/test/index.html @@ -22,7 +22,7 @@ 'app-location.html', 'test-observer-app.html', 'test-app-example-1.html', - + 'app-route-optional-params.html' ]); From 52fc833f091c91f482f669b52d2bdbdb62574367 Mon Sep 17 00:00:00 2001 From: Jose Ramos Date: Thu, 7 Sep 2017 12:03:01 +0200 Subject: [PATCH 3/3] Update index.html Revert changes --- test/index.html | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/test/index.html b/test/index.html index 1a1ba82..d410212 100644 --- a/test/index.html +++ b/test/index.html @@ -17,12 +17,17 @@