-
Notifications
You must be signed in to change notification settings - Fork 635
Description
问题描述
问题的具体描述
子应用路由加载2级后,router.back 子应用页面不加载
复现步骤
1.微前端模式下,主应用加载子应用postloan子应用,postloan子应用内进入A页面,继续router.push 进入B页面,b页面内执行$router.back(),可以看到url已经改变,但是页面无渲染,点击2次后直接返回了主应用的首页。
2.若在微前端模式下,拼接好路径直接进入postloan子应的A页面,继续router.push 进入B页面,b页面内执行$router.back() 正常。
上传截图
主应用:::
// micro-app 微前端配置:https://jd-opensource.github.io/micro-app/docs.html#/zh-cn/api/base-app
const domain = window.location.origin
microApp.start({
iframeSrc: ${domain}/main/empty.html,
'disable-memory-router': false,
'router-mode': 'native-scope',
'keep-router-state': true,
// destroy: true,
// 关闭对子应用请求的拦截
'disable-patch-request': true,
fetch(url, options, appName) {
return window
.fetch(url, options)
.then(res => {
return res.text()
})
.catch(e => {
if (e.toString().indexOf('Failed to fetch') > -1) {
store.commit('SET_LOAD_MICRO', false)
store.commit('DEL_TAG', store.getters.tag)
router.push('/wel/index')
store.commit('SET_FAILED_APP', appName.replace('sub-', ''))
globalNotify('子应用资源加载不完整', '这可能导致应用功能缺失,请及时联系运维处理', 'error')
}
})
},
preFetchApps: [
// { name: 'sub-crm', url: 'http://localhost:8091' },
],
plugins: {}
})
/**
- micro-app 配置注入主应用的路由;子应用可使用主应用的路由进行跳转
- https://jd-opensource.github.io/micro-app/docs.html#/zh-cn/router?id=navigation
- */
microApp.router.setBaseAppRouter(router)
const globalDataListener = ({ status, code, logs }) => {
if (status == 401 || status === 426) {
store.dispatch('LogOut').then(() => {
if (import.meta.env.VITE_APP_CONST === 'pro') {
window.location.replace(import.meta.env.VITE_APP_PORTALURL)
} else {
globalNotify('请重新登录', '', 'error', true)
router.push({ path: '/login' })
}
})
return
}
if (status === 200 && code !== 0) {
if (code === 401) {
store.dispatch('LogOut').then(() => {
if (import.meta.env.VITE_APP_CONST === 'pro') {
window.location.replace(import.meta.env.VITE_APP_PORTALURL)
} else {
globalNotify('服务未授权,请重新登录', '', 'error', true)
router.push({ path: '/login' })
}
})
return
}
store.commit('ADD_LOGS', logs)
}
}
microApp.addGlobalDataListener(globalDataListener, true)
注册子应用
<micro-app
name="sub-postloan"
:url="url"
baseroute="/postloan"
inline
:data="postloanData"
@created="subCreated"
@mounted="subMounted"
@Datachange="subDataChange"
destroy
环境信息
- micro-app版本:'1.0.0-rc.28'
- 主应用前端框架&版本: "vue": "^3.4.31", "vue-router": "^4.6.3",
- 子应用前端框架&版本: "vue": "^2.6.12", "vue-router": "^3.4.9",
- 构建工具&版本:主应用"vite": "^5.4.21", 子应用vue-cli-service