(url, basePath, hashPrefix)
| 5105 | |
| 5106 | |
| 5107 | function convertToHashbangUrl(url, basePath, hashPrefix) { |
| 5108 | var match = matchUrl(url); |
| 5109 | |
| 5110 | // already hashbang url |
| 5111 | if (decodeURIComponent(match.path) == basePath && !isUndefined(match.hash) && |
| 5112 | match.hash.indexOf(hashPrefix) === 0) { |
| 5113 | return url; |
| 5114 | // convert html5 url -> hashbang url |
| 5115 | } else { |
| 5116 | var search = match.search && '?' + match.search || '', |
| 5117 | hash = match.hash && '#' + match.hash || '', |
| 5118 | pathPrefix = pathPrefixFromBase(basePath), |
| 5119 | path = match.path.substr(pathPrefix.length); |
| 5120 | |
| 5121 | if (match.path.indexOf(pathPrefix) !== 0) { |
| 5122 | throw Error('Invalid url "' + url + '", missing path prefix "' + pathPrefix + '" !'); |
| 5123 | } |
| 5124 | |
| 5125 | return composeProtocolHostPort(match.protocol, match.host, match.port) + basePath + |
| 5126 | '#' + hashPrefix + path + search + hash; |
| 5127 | } |
| 5128 | } |
| 5129 | |
| 5130 | |
| 5131 | /** |
no test coverage detected