Ant Design Pro 部署到非根目录配置

使用目前最新的 AntDesignPro 脚手架:2.1.1

1.config/config.js中

export default { // 中加上如下:

history: 'hash', // 采用hash路由:#/xxx的形式

base:'./',

publicPath:'./',

(会自动将/static/xxx.jpg之类的和umi.js中的a.p="/"及index.html中window.routerBase中该值进行替换)

2.生成出来的dist目录中index.html所有路径改成./xxx这种形式。(可能color.less路径还没有变成./)

3.request.js

src/utils/request.js中

return fetch(url, newOptions)

改为

return fetch("."+url, newOptions)

所有ajax请求根目录从.开始

4.注销后重新登录url错误问题

src/models/login.js :

routerRedux.push({
  pathname: '/user/login',
  search: stringify({
    redirect: window.location.href,
  }),
})

修改为

routerRedux.push({
  pathname: '/user/login',
  search: stringify({
    redirect: window.location.hash,
  }),
})

你可能感兴趣的:(Ant Design Pro 部署到非根目录配置)