diff --git a/api/mount.js b/api/mount.js index 0cebfcf6..2178505a 100644 --- a/api/mount.js +++ b/api/mount.js @@ -10,7 +10,7 @@ module.exports = function(redrawService) { return } - if (component.view == null) throw new Error("m.mount(element, component) expects a component, not a vnode") + if (component.view == null && typeof component !== "function") throw new Error("m.mount(element, component) expects a component, not a vnode") var run = function() { redrawService.render(root, Vnode(component)) diff --git a/api/router.js b/api/router.js index b4690966..c182008f 100644 --- a/api/router.js +++ b/api/router.js @@ -21,11 +21,12 @@ module.exports = function($window, redrawService) { routeService.defineRoutes(routes, function(payload, params, path) { var update = lastUpdate = function(routeResolver, comp) { if (update !== lastUpdate) return - component = comp != null && typeof comp.view === "function" ? comp : "div", attrs = params, currentPath = path, lastUpdate = null + component = comp != null && (typeof comp.view === "function" || typeof comp === "function")? comp : "div" + attrs = params, currentPath = path, lastUpdate = null render = (routeResolver.render || identity).bind(routeResolver) run() } - if (payload.view) update({}, payload) + if (payload.view || typeof payload === "function") update({}, payload) else { if (payload.onmatch) { Promise.resolve(payload.onmatch(params, path)).then(function(resolved) {