fix: browser history
This commit is contained in:
parent
a014b4e6cb
commit
f709c50809
5 changed files with 34 additions and 22 deletions
|
@ -1,31 +1,20 @@
|
|||
import {Linking} from 'react-native'
|
||||
import {isIOS, isAndroid, isNative, isWeb} from './detection'
|
||||
import {createBrowserHistory, createMemoryHistory} from 'history'
|
||||
import {isNative, isWeb} from './detection'
|
||||
|
||||
export function makeAppUrl(path = '') {
|
||||
if (isIOS) {
|
||||
return `bskyapp://${path}`
|
||||
} else if (isAndroid) {
|
||||
return `bsky://app${path}`
|
||||
} else {
|
||||
// @ts-ignore window exists -prf
|
||||
return `${window.location.origin}${path}`
|
||||
}
|
||||
}
|
||||
|
||||
export function extractHashFragment(url: string): string {
|
||||
return url.split('#')[1] || ''
|
||||
}
|
||||
|
||||
export async function getInitialURL(): Promise<string> {
|
||||
export async function getInitialURL(): Promise<string | undefined> {
|
||||
if (isNative) {
|
||||
const url = await Linking.getInitialURL()
|
||||
if (url) {
|
||||
return url
|
||||
}
|
||||
return makeAppUrl()
|
||||
return undefined
|
||||
} else {
|
||||
// @ts-ignore window exists -prf
|
||||
return window.location.toString()
|
||||
if (window.location.pathname !== '/') {
|
||||
return window.location.pathname
|
||||
}
|
||||
return undefined
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -35,3 +24,11 @@ export function clearHash() {
|
|||
window.location.hash = ''
|
||||
}
|
||||
}
|
||||
|
||||
export function getHistory() {
|
||||
if (isWeb) {
|
||||
return createBrowserHistory()
|
||||
} else {
|
||||
return createMemoryHistory()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue