复盘【ToC端 问题】
一:开发ToC端,新建 EE 类项目后, Router 修改问题
开发 EE类项目的时候,再 router/index.js 中直接判断是否是EE的项目,和非EE类项目。代码如下
if (process.env.NODE_ENV === "production") {
// 线上环境
// // 首先判断当前的 项目是否为EE的项目
let project_flag = true
if (PROJECT_SETTINGS['ee']['domain'] === cur_domain) {
console.log('===现在是EE的项目=== judge children')
for (const i in PROJECT_SETTINGS['ee'].children) {
if (PROJECT_SETTINGS['ee'].children[i].path1 === cur_path1) {
project_flag = false
console.log('当前项目是 EE 项目子项目')
console.log(PROJECT_SETTINGS['ee'])
cur_project_name = cur_path1
onProjectChanged(cur_project_name)
}
}
console.log("===cur_project_name===", cur_project_name)
console.log("===cur_path1===", cur_path1 , '/', cur_path1, '/', !whiteList.includes(cur_path1), '/', cur_path1, '/', cur_project_name)
console.log("===cur_path1 && !whiteList.includes(cur_path1) && cur_path1 !== cur_project_name===", cur_path1 && !whiteList.includes(cur_path1) && cur_path1 !== cur_project_name)
if (cur_path1 && !whiteList.includes(cur_path1) && cur_path1 !== cur_project_name) {
// 访问与域名不符的一级目录路径时,跳转到当前域名对应项目的home页面
next({path: '/404'})
}
} else {
for (let project_name in PROJECT_SETTINGS) {
console.log(project_name)
if (PROJECT_SETTINGS[project_name]['domain'] === cur_domain) {
cur_project_name = project_name
onProjectChanged(project_name)
break
}
}
if (cur_path1 && !whiteList.includes(cur_path1) && cur_path1 !== cur_project_name) {
// 访问与域名不符的一级目录路径时,跳转到当前域名对应项目的home页面
next({path: '/404'})
}
}
} else {
console.log('开发/测试环境', to)
console.log(cur_path1, '===cur_path1===')
if (!cur_path1) {
cur_path1 = 'msf'
}
// console.log(whiteList, '===whiteList===')
if (whiteList.includes(cur_path1)) {
let redirect = getQueryString('redirect')
if (redirect) {
// 一级目录不是项目名称时(即登录/注册等路径时),根据重定向参数判断当前目录
let redirect_list = decodeURIComponent(redirect).split('/')
cur_path1 = redirect_list[1]
// console.log('当前一级目录1', cur_path1)
onProjectChanged(cur_path1)
} else {
// console.log('当前一级目录2', cur_path1)
// TODO 没有重定向路径的,待确认默认跳转到哪儿
}
} else {
// console.log('当前一级目录3', cur_path1)
onProjectChanged(cur_path1)
}
}
二、遇到问题
在判断中,慎用 return ,在第三次修改中,因为 return 的使用,直接在判断完毕 EE的项目之后,进行了return ,导致后边的 router 的 next() 函数无法正常调用,也就是导致直接报 404 错误页面。