Support non-root base path

This commit is contained in:
Pierre-Yves Gerardy 2016-05-30 00:07:52 +02:00
parent 3bb0a6287f
commit 297e343264
4 changed files with 8 additions and 6 deletions

View file

@ -36,7 +36,7 @@ module.exports = function($window) {
switch (type) { switch (type) {
case "#": return normalize("hash").slice(prefix.length) case "#": return normalize("hash").slice(prefix.length)
case "?": return normalize("search").slice(prefix.length) + normalize("hash") case "?": return normalize("search").slice(prefix.length) + normalize("hash")
default: return normalize("pathname") + normalize("search") + normalize("hash") default: return normalize("pathname").slice(prefix.length) + normalize("search") + normalize("hash")
} }
} }

View file

@ -5,7 +5,7 @@ var pushStateMock = require("../../test-utils/pushStateMock")
var Router = require("../../router/router") var Router = require("../../router/router")
o.spec("Router.defineRoutes", function() { o.spec("Router.defineRoutes", function() {
void ["#", "?", "", "#!", "?!"].forEach(function(prefix) { void ["#", "?", "", "#!", "?!", "/foo"].forEach(function(prefix) {
o.spec("using prefix `" + prefix + "`", function() { o.spec("using prefix `" + prefix + "`", function() {
var $window, router, onRouteChange, onFail var $window, router, onRouteChange, onFail

View file

@ -5,7 +5,7 @@ var pushStateMock = require("../../test-utils/pushStateMock")
var Router = require("../../router/router") var Router = require("../../router/router")
o.spec("Router.getPath", function() { o.spec("Router.getPath", function() {
void ["#", "?", "", "#!", "?!"].forEach(function(prefix) { void ["#", "?", "", "#!", "?!", '/foo'].forEach(function(prefix) {
o.spec("using prefix `" + prefix + "`", function() { o.spec("using prefix `" + prefix + "`", function() {
var $window, router, onRouteChange, onFail var $window, router, onRouteChange, onFail

View file

@ -5,7 +5,7 @@ var pushStateMock = require("../../test-utils/pushStateMock")
var Router = require("../../router/router") var Router = require("../../router/router")
o.spec("Router.setPath", function() { o.spec("Router.setPath", function() {
void ["#", "?", "", "#!", "?!"].forEach(function(prefix) { void ["#", "?", "", "#!", "?!", "/foo"].forEach(function(prefix) {
o.spec("using prefix `" + prefix + "`", function() { o.spec("using prefix `" + prefix + "`", function() {
var $window, router, onRouteChange, onFail var $window, router, onRouteChange, onFail
@ -78,8 +78,10 @@ o.spec("Router.setPath", function() {
router.defineRoutes({"/test": {data: 1}, "/other": {data: 2}}, onRouteChange, onFail) router.defineRoutes({"/test": {data: 1}, "/other": {data: 2}}, onRouteChange, onFail)
router.setPath("/other", null, {replace: false}) router.setPath("/other", null, {replace: false})
$window.history.back() $window.history.back()
o($window.location.href).equals("http://localhost/" + (prefix ? prefix + "/" : "") + "test") var slash = prefix[0] === "/" ? "" : "/"
o($window.location.href).equals("http://localhost" + slash + (prefix ? prefix + "/" : "") + "test")
}) })
}) })
}) })