diff options
Diffstat (limited to 'public/assets/js/vendor/view/router.js')
| -rw-r--r-- | public/assets/js/vendor/view/router.js | 35 |
1 files changed, 23 insertions, 12 deletions
diff --git a/public/assets/js/vendor/view/router.js b/public/assets/js/vendor/view/router.js index b0e2f84..3b0d939 100644 --- a/public/assets/js/vendor/view/router.js +++ b/public/assets/js/vendor/view/router.js @@ -1,21 +1,34 @@ var Router = View.extend({ + routeByHash: false, + go: function(url){ this.parseRoute(url) }, + + pushState: function(url){ + if (this.routeByHash) { + window.location.hash = url + } + else if (window.history) { + window.history.pushState(null, null, url) + } + }, route: function(){ - this.originalPath = window.location.pathname - this.parseRoute(window.location.pathname) - }, - - pushState: function(pathname){ - window.history.pushState({}, "", pathname) + var path = this.routeByHash ? window.location.hash.substr(0) : window.location.pathname + path = path || "/" + this.originalPath = path + this.parseRoute(path) }, parseRoute: function(pathname){ + + pathname = pathname.replace(/^#/, "") + + if (pathname[0] !== "/") { pathname = "/" + pathname } - var routes = is_mobile && this.mobileRoutes ? this.mobileRoutes : this.routes, + var routes = this.routes, path = pathname.split("/"); for (var i = 0; i < path.length; i++) { @@ -23,7 +36,7 @@ var Router = View.extend({ path[i] = null } } - + if (pathname in routes) { this[this.routes[pathname]]() return @@ -62,10 +75,8 @@ var Router = View.extend({ } } } - - if (is_mobile) { - window.location.href = "/" - } + // Redirect to root on 404 + window.location = '/' } }) |
