ANT DESIGN PRO V4 编译设置路由前缀

package.json

    "build": "cross-env PUBLIC_PATH=/cms/ umi build",
    "start": "cross-env PORT=8002 PUBLIC_PATH=/cms/ umi dev",

config.js

const {
    
     PUBLIC_PATH } = process.env;

export default defineConfig({
    
    
  hash: true,
  history: {
    
     type: 'hash' },
  base: PUBLIC_PATH,
  publicPath: PUBLIC_PATH,
  manifest: {
    
    
    basePath: PUBLIC_PATH,
  },
})

permission.js

/**
 * 当前页面是否是有权限的页面
 * @returns {boolean} true表示当前页面要有登录
 */
export const isAuthorizedPage = () => {
    
    
  const url = ['user']; // 不需要登录页面的前置
  const {
    
     hash } = window.location;
  const target = url.filter((d) => d === hash.split('/')[2]);
  return target.length === 0;
};

global.js


// 登录
    effects: {
    
    
    // 登录
    *login({
    
     payload }, {
    
     call, put }) {
    
    
      const response = yield call(api.login, payload);
      if (response.success === true) {
    
    
        const {
    
     data } = response;
        removeCookie();
        setCookie('user', JSON.stringify(data));
        yield put({
    
    
          type: 'updateState',
          payload: {
    
    
            currentUser: data,
          },
        });
        // 权限
        yield put({
    
    
          type: 'addAuthority',
          payload: {
    
    
            roles: data.roles,
          },
        });
        // 路由重定向
        const params = getPageQuery();
        const {
    
     redirect } = params;
        window.location.href = redirect || '/';
      }
    },

猜你喜欢

转载自blog.csdn.net/m0_37859032/article/details/112602658