有一个if条件结果console.log他们什么也没打印,并出现在浏览器控制台 TypeError: Cannot read property 'to' of undefined 上instance.interceptors.response.use( (res) => { const { pathname } = window.location; const isRedirect = res.status === HTTP_TEMPORARY_REDIRECT; const data = { isRedirect, data: res.data }; if (isRedirect) { console.log(`pathname: ${pathname}`); console.log(`isRedirect: ${isRedirect}`); const { redirectDataSource: { to: redirectRoute, ...redirectData } } const { redirectDataSource: { to: redirectRoute, ...redirectData }, } = res.data.error || res.data; console.log(`redirectRoute: ${redirectRoute}`); console.log(`redirectDataSource: ${redirectDataSource}`); } return Promise.resolve(data); }, ...
1 回答
POPMUISE
TA贡献1765条经验 获得超5个赞
redirectDataSource如果未定义,您需要添加默认值
let res = {
data: {
error: undefined,
redirectDataSource: undefined
}
}
const {
redirectDataSource: {
to: redirectRoute,
} = {to: 'defaultValue'}
} = res.data.error || res.data;
console.log(redirectRoute)
添加回答
举报
0/150
提交
取消