24 lines
701 B
JavaScript
24 lines
701 B
JavaScript
const HOME_URL = '/pages/home/home'
|
|
|
|
export function getCurrentRoute() {
|
|
if (typeof getCurrentPages !== 'function') return ''
|
|
const pages = getCurrentPages()
|
|
const currentPage = pages[pages.length - 1]
|
|
return currentPage ? currentPage.route || '' : ''
|
|
}
|
|
|
|
export function navigateBackOr(fallbackUrl = HOME_URL) {
|
|
const pages = typeof getCurrentPages === 'function' ? getCurrentPages() : []
|
|
if (pages.length > 1) {
|
|
uni.navigateBack({ fail: () => uni.reLaunch({ url: fallbackUrl }) })
|
|
return
|
|
}
|
|
uni.reLaunch({ url: fallbackUrl })
|
|
}
|
|
|
|
export function navigateToUnique(url) {
|
|
const route = url.split('?')[0].replace(/^\//, '')
|
|
if (getCurrentRoute() === route) return
|
|
uni.navigateTo({ url })
|
|
}
|