Skip to content

Commit ec5b03b

Browse files
touletandead-claudia
authored andcommitted
set trailing slash optional in route matching
1 parent a3d0711 commit ec5b03b

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

api/tests/test-router.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,30 @@ o.spec("route", function() {
225225
)
226226
})
227227

228+
o("remove trailing slash to match route if it is before rest operator match (...) ", function() {
229+
$window.location.href = prefix + "/test/d/"
230+
route(root, "/test/:a...", {
231+
"/test/:a" : {
232+
view: lock(function(vnode) {
233+
return JSON.stringify(route.param()) + " " +
234+
JSON.stringify(vnode.attrs) + " " +
235+
route.get()
236+
})
237+
},
238+
"/test/:a..." : {
239+
view: lock(function(vnode) {
240+
return JSON.stringify(route.param()) + " " +
241+
JSON.stringify(vnode.attrs) + " " +
242+
route.get()
243+
})
244+
},
245+
})
246+
247+
o(root.firstChild.nodeValue).equals(
248+
'{"a":"d"} {"a":"d"} /test/d/'
249+
)
250+
})
251+
228252
o("handles route with search", function() {
229253
$window.location.href = prefix + "/test?a=b&c=d"
230254
route(root, "/test", {

pathname/compileTemplate.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ module.exports = function(template) {
2424
if (extra === ".") return "([^/]+)\\."
2525
return "([^/]+)" + (extra || "")
2626
}
27-
) + "$")
27+
) + "\\/?$")
2828
return function(data) {
2929
// First, check the params. Usually, there isn't any, and it's just
3030
// checking a static set.

0 commit comments

Comments
 (0)