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-1)&&!el.target&&sameOrigin(el.href)){var path=el.pathname+el.search+(el.hash||""),orig=path;0===path.indexOf(base)&&(path=path.substr(base.length)),hashbang&&(path=path.replace("#!","")),base&&orig===path||(e.preventDefault(),page.show(orig))}}}}function which(e){return e=e||window.event,null===e.which?e.button:e.which}function sameOrigin(href){var origin=location.protocol+"//"+location.hostname;return location.port&&(origin+=":"+location.port),href&&0===href.indexOf(origin)}function parse(str){for(var res,tokens=[],key=0,index=0,path="";null!=(res=PATH_REGEXP.exec(str));){var m=res[0],escaped=res[1],offset=res.index;if(path+=str.slice(index,offset),index=offset+m.length,escaped)path+=escaped[1];else{path&&(tokens.push(path),path="");var prefix=res[2],name=res[3],capture=res[4],group=res[5],suffix=res[6],asterisk=res[7],repeat="+"===suffix||"*"===suffix,optional="?"===suffix||"*"===suffix,delimiter=prefix||"/",pattern=capture||group||(asterisk?".*":"[^"+delimiter+"]+?");tokens.push({name:name||key++,prefix:prefix||"",delimiter:delimiter,optional:optional,repeat:repeat,pattern:escapeGroup(pattern)})}}return index0){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&&"undefined"==typeof 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++];return fn?void fn(prev,nextExit):nextEnter()}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;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