Merge pull request #88 from yolk/route-trailing-slash

Added support for trailing slashes in routes
This commit is contained in:
Leo Horie 2014-05-24 13:30:00 -04:00
commit c4e13384db
2 changed files with 18 additions and 3 deletions

View file

@ -315,11 +315,11 @@ Mithril = m = new function app(window) {
for (var route in router) {
if (route == path) return !void m.module(root, router[route])
var matcher = new RegExp("^" + route.replace(/:[^\/]+?\.{3}/g, "(.*?)").replace(/:[^\/]+/g, "([^\\/]+)") + "$")
var matcher = new RegExp("^" + route.replace(/:[^\/]+?\.{3}/g, "(.*?)").replace(/:[^\/]+/g, "([^\\/]+)") + "\/?$")
if (matcher.test(path)) {
return !void path.replace(matcher, function() {
var keys = route.match(/:[^\/]+/g)
var keys = route.match(/:[^\/]+/g) || []
var values = [].slice.call(arguments, 1, -2)
for (var i = 0; i < keys.length; i++) routeParams[keys[i].replace(/:|\./g, "")] = decodeURIComponent(values[i])
m.module(root, router[route])
@ -501,4 +501,4 @@ Mithril = m = new function app(window) {
if (typeof module != "undefined" && module !== null) module.exports = m
if (typeof define == "function" && define.amd) define(function() {return m})
;;;
;;;