Skip to content

Commit

Permalink
Solve this problem: micro-zoe/micro-app#1055
Browse files Browse the repository at this point in the history
  • Loading branch information
gudaoxuri committed Jan 12, 2024
1 parent 71db3c8 commit f26c4c6
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 14 deletions.
6 changes: 3 additions & 3 deletions child_apps/vite-vue3/src/router.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createRouter, createWebHistory } from 'vue-router'
import { createRouter, createWebHashHistory, createWebHistory } from 'vue-router'
import Home from './views/home.vue'

const routes = [
Expand All @@ -15,8 +15,8 @@ const routes = [
]

const router = createRouter({
history: createWebHistory('/child'),
routes
history: createWebHistory('/app1'),
routes
})

export default router
2 changes: 1 addition & 1 deletion child_apps/vite-vue3/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ export default defineConfig({
},
base: `http://172.30.111.50:8080/child/`,
build: {
outDir: 'vite/child',
outDir: 'vite',
},
})
2 changes: 1 addition & 1 deletion main_apps/vite-vue3/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.0.0",
"scripts": {
"dev": "vite",
"build": "vue-tsc --noEmit && vite build",
"build": "vite build",
"serve": "vite preview"
},
"dependencies": {
Expand Down
5 changes: 1 addition & 4 deletions main_apps/vite-vue3/src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,13 @@ const routes: Array<RouteRecordRaw> = [
component: Home,
},
{
// 因为主应用为history路由,appname-vite子应用是hash路由,这里配置略微不同
// 已解决带参数时页面丢失的问题
path: '/app1',
path: '/app1/:pathMatch(.*)*',
name: 'vite',
component: () => import('./views/child.vue'),
}
]

const router = createRouter({
// 设置主应用基础路由为main-vite(用于后续部署),则子应用基础路由(baseroute)为/main-vite/xxx
history: createWebHistory(import.meta.env.BASE_URL),
routes
})
Expand Down
23 changes: 18 additions & 5 deletions main_apps/vite-vue3/src/views/child.vue
Original file line number Diff line number Diff line change
@@ -1,15 +1,28 @@
<script lang="ts" setup>
import { ref } from 'vue'
const url = ref()
const replaceUrl = () => {
let actualUrl = window.location.href
actualUrl = actualUrl.replace('/app1', '/child')
url.value = actualUrl
}
replaceUrl()
console.log('加载子应用:'+url.value)
</script>


<template>
<div>
主应用区域
<micro-app
name='appname-vite'
url='http://172.30.111.50:8080/child/'
:url='url'
inline
disablesandbox
></micro-app>
</div>
</template>

<script lang="ts" setup>
console.log('加载主应用')
</script>
56 changes: 56 additions & 0 deletions nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@

#user nobody;
worker_processes 1;

#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;

#pid logs/nginx.pid;


events {
worker_connections 1024;
}


http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;

server {
listen 8080;
server_name 172.30.111.50;

location / {
proxy_pass http://127.0.0.1:3000;
}

location ~* ^/child/(.*)$ {
proxy_pass http://127.0.0.1:4007/$1;
}
}

server {
listen 3000;
server_name localhost;

root C:\\...\\main_apps\\vite-vue3\\main-vite;
index index.html;
try_files $uri $uri/ /index.html =404;

}

server {
listen 4007;
server_name localhost;

root C:\\...\\child_apps\\vite-vue3\\vite;
index index.html;
try_files $uri $uri/ /index.html =404;
}


}

0 comments on commit f26c4c6

Please sign in to comment.