define([],function(){"use strict";function page(path,fn){if("function"==typeof path)return page("*",path);if("function"==typeof fn)for(var route=new Route(path),i=1;i=href.indexOf("#!")&&(url+=location.search)}else url=location.pathname+location.search+location.hash;page.replace(url,null,!0,dispatch)}},page.stop=function(){running&&(page.current="",page.len=0,running=!1,document.removeEventListener(clickEvent,onclick,!1),window.removeEventListener("popstate",onpopstate,!1))},page.show=function(path,state,dispatch,push,isBack){var ctx=new Context(path,state);return ctx.isBack=isBack,page.current=ctx.path,!1!==dispatch&&page.dispatch(ctx),!1!==ctx.handled&&!1!==push&&ctx.pushState(),ctx},page.restorePreviousState=function(){prevContext=prevPageContext,page.show(prevContext.pathname,prevContext.state,!1,!0,!1)},page.back=function(path,state){if(enableHistory)return void history.back();if(page.len>0){if(enableHistory)history.back();else if(backStack.length>2){backStack.length--;var previousState=backStack[backStack.length-1];page.show(previousState.path,previousState.state,!0,!1,!0)}page.len--}else path?setTimeout(function(){page.show(path,state)}):setTimeout(function(){page.show(base,state)})},page.enableNativeHistory=function(){return enableHistory},page.canGoBack=function(){return enableHistory?history.length>1:(page.len||0)>0},page.redirect=function(from,to){"string"==typeof from&&"string"==typeof to&&page(from,function(e){setTimeout(function(){page.replace(to)},0)}),"string"==typeof from&&void 0===to&&setTimeout(function(){page.replace(from)},0)},page.replace=function(path,state,init,dispatch,isBack){var ctx=new Context(path,state);return ctx.isBack=isBack,page.current=ctx.path,ctx.init=init,ctx.save(),!1!==dispatch&&page.dispatch(ctx),ctx},page.dispatch=function(ctx){function nextExit(){var fn=page.exits[j++];if(!fn)return nextEnter();fn(prev,nextExit)}function nextEnter(){var fn=page.callbacks[i++];return ctx.path!==page.current?void(ctx.handled=!1):fn?void fn(ctx,nextEnter):unhandled(ctx)}var prev=prevContext,i=0,j=0;prevPageContext=prevContext,prevContext=ctx,prev?nextExit():nextEnter()},page.exit=function(path,fn){if("function"==typeof path)return page.exit("*",path);for(var route=new Route(path),i=1;i