We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 89c0786 commit 008518eCopy full SHA for 008518e
1 file changed
src/url-util.js
@@ -1,13 +1,19 @@
1
// @flow
2
/* eslint-env browser */
3
4
-export const currentUrl = (): string => window.location.href
+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
11
12
export const currentUrlNoParams = (): string =>
- window.location.origin + window.location.pathname
13
+ getLocation().origin + getLocation().pathname
14
15
export const navigateTo = (url: string) => {
- window.location.href = url
16
+ getLocation().href = url
17
}
18
19
export const originOf = (url: string): string => new URL(url).origin
0 commit comments