export default function (options) {
	var routes = options.view

	return {
		model: {
			router: {
				location: location.pathname
			}
		},
		effects: {
			router: {
				go: function (model, actions, data) {
					actions.router.setLocation(data)
					history.pushState({}, "", data)
				}
			}
		},
		reducers: {
			router: {
				setLocation: function (model, data) {
					model.router.location = data
					return model
				}
			}
		},
		subscriptions: [
			function (_, actions) {
				window.addEventListener("popstate", function () {
					actions.router.setLocation(location.pathname)
				})
			}
		],
		hooks: {
			onRender: function (model, view) {
				return match(routes, model.router.location)
			}
		}
	}

	function match(routes, path) {
		for (var route in routes) {
			if (route === "*") {
				continue
			}

			var re = regexify(route), params = {}, match

			path.replace(new RegExp(re.re, "g"), function () {
				for (var i = 1; i < arguments.length - 2; i++) {
					params[re.keys.shift()] = arguments[i]
				}

				match = function (model, actions) {
					return routes[route](model, actions, params)
				}
			})

			if (match) {
				return match
			}
		}

		return routes["*"]
	}

	function regexify(path) {
		var keys = [], re = "^" + path
			.replace(/\//g, "\\/")
			.replace(/:([A-Za-z0-9_]+)/g, function (_, key) {
				keys.push(key)
				return "([A-Za-z0-9_]+)"
			}) + "/?$"

		return { re: re, keys: keys }
	}
}

@@ -702,26 +702,27 @@
 %09%09%09%7D%0A%09%09%7D%0A%09%7D%0A
+%7D%0A
 %0A
-%09
 function mat
@@ -740,17 +740,16 @@
 path) %7B%0A
-%09
 %09for (va
@@ -769,17 +769,16 @@
 utes) %7B%0A
-%09
 %09%09if (ro
@@ -795,17 +795,16 @@
 %22) %7B%0A%09%09%09
-%09
 continue
@@ -806,21 +806,19 @@
 tinue%0A%09%09
-%09
 %7D%0A%0A
-%09
 %09%09var re
@@ -857,17 +857,16 @@
  match%0A%0A
-%09
 %09%09path.r
@@ -913,17 +913,16 @@
 () %7B%0A%09%09%09
-%09
 for (var
@@ -966,17 +966,16 @@
 ) %7B%0A%09%09%09%09
-%09
 params%5Br
@@ -1008,21 +1008,19 @@
 s%5Bi%5D%0A%09%09%09
-%09
 %7D%0A%0A
-%09
 %09%09%09match
@@ -1050,25 +1050,24 @@
 ions) %7B%0A%09%09%09%09
-%09
 return route
@@ -1106,19 +1106,16 @@
 %0A%09%09%09
-%09
 %7D%0A
-%09
 %09%09%7D)%0A%0A
-%09
 %09%09if
@@ -1124,25 +1124,24 @@
 match) %7B%0A%09%09%09
-%09
 return match
@@ -1147,17 +1147,14 @@
 h%0A%09%09
-%09
 %7D%0A
-%09
 %09%7D%0A%0A
-%09
 %09ret
@@ -1169,21 +1169,19 @@
 es%5B%22*%22%5D%0A
-%09
 %7D%0A%0A
-%09
 function
@@ -1198,17 +1198,16 @@
 path) %7B%0A
-%09
 %09var key
@@ -1230,17 +1230,16 @@
  + path%0A
-%09
 %09%09.repla
@@ -1257,17 +1257,16 @@
 %5C%5C/%22)%0A%09%09
-%09
 .replace
@@ -1310,17 +1310,16 @@
 y) %7B%0A%09%09%09
-%09
 keys.pus
@@ -1325,17 +1325,16 @@
 sh(key)%0A
-%09
 %09%09%09retur
@@ -1353,17 +1353,16 @@
 -9_%5D+)%22%0A
-%09
 %09%09%7D) + %22
@@ -1367,17 +1367,16 @@
  %22/?$%22%0A%0A
-%09
 %09return 
@@ -1398,13 +1398,10 @@
  keys %7D%0A
-%09%7D%0A
 %7D%0A

Move match and regexify outside of Router function.