mirror of
https://github.com/MercuryWorkshop/scramjet.git
synced 2025-05-13 14:30:02 -04:00
decode urls on history api, add url object support to the url rewriter
This commit is contained in:
parent
4fedcea1d4
commit
78813da771
2 changed files with 13 additions and 6 deletions
|
@ -11,7 +11,11 @@ function canParseUrl(url: string, origin?: URL) {
|
|||
}
|
||||
|
||||
// something is broken with this but i didn't debug it
|
||||
export function encodeUrl(url: string, origin?: URL) {
|
||||
export function encodeUrl(url: string | URL, origin?: URL) {
|
||||
if (url instanceof URL) {
|
||||
url = url.toString()
|
||||
}
|
||||
|
||||
if (!origin) {
|
||||
origin = new URL(self.$scramjet.config.codec.decode(location.href.slice((location.origin + self.$scramjet.config.prefix).length)));
|
||||
}
|
||||
|
@ -26,7 +30,11 @@ export function encodeUrl(url: string, origin?: URL) {
|
|||
}
|
||||
|
||||
// something is also broken with this but i didn't debug it
|
||||
export function decodeUrl(url: string) {
|
||||
export function decodeUrl(url: string | URL) {
|
||||
if (url instanceof URL) {
|
||||
url = url.toString()
|
||||
}
|
||||
|
||||
if (/^(#|about|data|mailto|javascript)/.test(url)) {
|
||||
return url;
|
||||
} else if (canParseUrl(url)) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue