React Umi3.x配合antd4.x 脚手架生成项目,修改默认起始页为登录页

#1

在寻访完各个网站博客后,目前网上现有的修改方案基本为以下几点:
1:util/authority.js getAuthority function中
getAuthority(str) {
return localStorage.getItem(‘antd-pro-authority’) || [ ‘admin’];
修改为
return localStorage.getItem(‘antd-pro-authority’) || [ ‘guest’];
或在最后return代码中
return authority || [‘admin’];修改为return authority || [‘guest’];
2:修改路由
{
path: ‘/’,
redirect: ‘/user/login’,
// redirect: ‘/dashboard/analysis’,
authority: [‘admin’, ‘user’],
},
个人目前使用得这两个方法在最新得antd4.x项目中都未能够有效的实现修改默认起始页,于偶然中修改如下代码,实现了默认启动页为登录页:
代码位置在BasicLayout.jsx
const authorized = getAuthorityFromRouter(props.route.routes, location.pathname || ‘/’) || {
authority: undefined,
};
修改为:
const authorized = getAuthorityFromRouter(props.route.routes, location.pathname || ‘/’) || {
authority: ‘guest’,
};

今天发现一个更加简单粗暴的方法:
修改utils.js 和authority.js如下代码:
export function setAuthority(authority) {
const proAuthority = typeof authority === ‘string’ ? [authority] : authority;
console.log(proAuthority);
localStorage.setItem(‘antd-pro-authority’, ‘[“guest”]’); // auto reload
// localStorage.setItem(‘antd-pro-authority’, JSON.stringify(proAuthority)); // auto reload
reloadAuthorized();
}
注释设置localstorage原有代码,直接设置为[‘guest’];
如有其它方法,欢迎各位指教~~~~