一、部署配置
qiankun微前端改造配置就不记录了,只记录部署需要的配置
mypro:自定义的子应用名称
1. 主应用配置
- (1).env文件
BASE_URL = /MicroBase/
- (2) vue.config.js文件
module.exports = {publicPath: process.env.BASE_URL,outputDir: 'MicroBase',... }
- (3)路由
export default new Router({base: process.env.BASE_URL,mode: 'history',... })
- (4)子应用注册信息
{"name": "myproApp","entry": "/MicroMypro/", // 子应用的 BASE_URL"entry_dev": "http://localhost:8080/","container": "#appContainer","activeRule": "app-mypro" }
2. 子应用配置
- (1).env文件
BASE_URL = /MicroMypro/
- (2) vue.config.js文件
module.exports = {publicPath: process.env.BASE_URL,outputDir: 'MicroMypro',... }
- (3)路由
export default new Router({base: window.__POWERED_BY_QIANKUN__ ? '/MicroMypro/app-mypro/' : '/',... })
二、容器目录
/usr/share/nginx/html|-- htmlMicroBase|-- MicroBase|-- htmlMicroMypro|-- MicroMypro
三、nginx配置
- 删除默认的
location /
配置# location / {# auth_request off;# root /usr/share/nginx/html/dist;# index index.html index.htm;# try_files $uri $uri/ /index.html;# add_header 'Access-Control-Allow-Origin' '*' always;# }
- 新增以下两项配置
location /MicroBase/ {auth_request off;root /usr/share/nginx/html/htmlMicroBase;index index.html index.htm;try_files $uri $uri/ /MicroBase/index.html;}location /MicroMypro/ {auth_request off;root /usr/share/nginx/html/htmlMicroMypro;index index.html index.htm;try_files $uri $uri/ /MicroMypro/index.html;}
四、浏览器访问路径(!重要!)
http://ip:port/MicroBase/
一定要带上/MicroBase/
,最后面的斜杠“/”不能丢,否则访问不到