Skip to content

Commit 008518e

Browse files
committed
Easy compatibility fix for non-browser.
See LDflex/LDflex-Comunica#12
1 parent 89c0786 commit 008518e

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

src/url-util.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
// @flow
22
/* eslint-env browser */
33

4-
export const currentUrl = (): string => window.location.href
4+
function getLocation() {
5+
return typeof window !== 'undefined'
6+
? window.location
7+
: { href: 'https://example.org/', pathname: '/', origin: 'example.org' }
8+
}
9+
10+
export const currentUrl = (): string => getLocation().href
511

612
export const currentUrlNoParams = (): string =>
7-
window.location.origin + window.location.pathname
13+
getLocation().origin + getLocation().pathname
814

915
export const navigateTo = (url: string) => {
10-
window.location.href = url
16+
getLocation().href = url
1117
}
1218

1319
export const originOf = (url: string): string => new URL(url).origin

0 commit comments

Comments
 (0)