前端页面获取不到url上参数值
定位:是否是hash模式下
**背景:**app应用,分子模块和子应用,两个共用同一套代码,但会存在差异,这时候需要去区分,我们可以从原生里获取到路径,这里会涉及到一个问题,由于我们原生子模块走的是安卓本地,所以用的是hash模式,hash模式下会导致,正常使用路由获取,获取不到问题。
解决方法一:
const isShowBack = ref("")
onMounted(async () => {
// eg: 你需要区分的参数是isShowBack
isShowBack.value = !!new URL(window.location.href).searchParams.get('isShowBack')
})
解决方法二:
路由配置文件router/index.js
js
/* hash模式下,url参数调整位置 */
if (window.location.search) {
const searchStr = window.location.search.replace('?', '')
let split = '?'
if (window.location.hash.indexOf('?') != -1) {
split = '&'
}
setTimeout(() => {
window.location.href = `${window.location.origin}${window.location.pathname}${window.location.hash}${split}${searchStr}`
}, 0)
}
export default router
页面正常使用route.query获取即可