Skip to content

请教子应用为History路由刷新报错的解决方案 #1055

Closed Answered by gudaoxuri
gudaoxuri asked this question in Q&A
Discussion options

You must be logged in to vote

已解决: gudaoxuri/tmp_micro_issue@f26c4c6

整体思路:

  • 无论访问的是基座应用还是子应用,浏览器URL必须都要命中基座应用,再由基座应用分发到子应用
  • 为了保证基座应用能分发子应用,那么必须要能访问到子应用,故需要将URL地址改写成子应用真实地址
  • 因此URL的地址与网关(模拟的Nginx)的地址是不同的

关键处理点:

  • 子应用的WebHistory的基础路径是基座应用访问该子应用的路由前缀,如:
基座应用使用app1前缀应该该子应用:
  {
    path: '/app1/:pathMatch(.*)*',
    name: 'vite',
    component: () => import('./views/child.vue'),
  }
https://github.com/gudaoxuri/tmp_micro_issue/blob/f26c4c696a3c6fe4f782837e3c901871f52c81f8/main_apps/vite-vue3/src/router.ts#L11-L13

子应用创建app1的URL前缀:
const router = createRouter({
  history: createWebHistory('/app1'),
    routes
})
https://github.com/gudaoxuri/tmp_micro_issue/blob/f26c4c696a3c6fe4f782837e3c901871f52c81f8/child_apps/vite-vue3/src…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by gudaoxuri
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant