MCPcopy
hub / github.com/MithrilJS/mithril.js / resolveRoute

Function resolveRoute

mithril.js:1407–1430  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1405 }
1406 router.defineRoutes = function(routes, resolve, reject) {
1407 function resolveRoute() {
1408 var path = router.getPath()
1409 var params = {}
1410 var pathname = parsePath(path, params, params)
1411 var state = $window.history.state
1412 if (state != null) {
1413 for (var k in state) params[k] = state[k]
1414 }
1415 for (var route0 in routes) {
1416 var matcher = new RegExp("^" + route0.replace(/:[^\/]+?\.{3}/g, "(.*?)").replace(/:[^\/]+/g, "([^\\/]+)") + "\/?$")
1417 if (matcher.test(pathname)) {
1418 pathname.replace(matcher, function() {
1419 var keys = route0.match(/:[^\/]+/g) || []
1420 var values = [].slice.call(arguments, 1, -2)
1421 for (var i = 0; i < keys.length; i++) {
1422 params[keys[i].replace(/:|\./g, "")] = decodeURIComponent(values[i])
1423 }
1424 resolve(routes[route0], params, path, route0)
1425 })
1426 return
1427 }
1428 }
1429 reject(path, params)
1430 }
1431 if (supportsPushState) $window.onpopstate = debounceAsync(resolveRoute)
1432 else if (router.prefix.charAt(0) === "#") $window.onhashchange = resolveRoute
1433 resolveRoute()

Callers 1

coreRouterFunction · 0.70

Calls 2

resolveFunction · 0.85
parsePathFunction · 0.70

Tested by

no test coverage detected