feat: 10.10线上最新代码提交
This commit is contained in:
19
src/components/ProtectedRoute.js
Normal file → Executable file
19
src/components/ProtectedRoute.js
Normal file → Executable file
@@ -25,17 +25,26 @@ const ProtectedRoute = ({ children }) => {
|
||||
);
|
||||
}
|
||||
|
||||
// 记录当前路径,登录后可以回到这里
|
||||
let currentPath = window.location.pathname + window.location.search;
|
||||
let redirectUrl = `/auth/signin?redirect=${encodeURIComponent(currentPath)}`;
|
||||
|
||||
// 检查是否已登录
|
||||
if (!isAuthenticated || !user) {
|
||||
// 记录当前路径,登录后可以回到这里
|
||||
const currentPath = window.location.pathname + window.location.search;
|
||||
const redirectUrl = `/auth/signin?redirect=${encodeURIComponent(currentPath)}`;
|
||||
|
||||
return <Navigate to={redirectUrl} replace />;
|
||||
}
|
||||
|
||||
// 已登录,渲染子组件
|
||||
return children;
|
||||
// return children;
|
||||
|
||||
// 更新逻辑 如果 currentPath 是首页 登陆成功后跳转到个人中心
|
||||
if (currentPath === '/' || currentPath === '/home') {
|
||||
currentPath = '/profile';
|
||||
redirectUrl = `/auth/signin?redirect=${encodeURIComponent(currentPath)}`;
|
||||
return <Navigate to={redirectUrl} replace />;
|
||||
} else { // 否则正常渲染
|
||||
return children;
|
||||
}
|
||||
};
|
||||
|
||||
export default ProtectedRoute;
|
||||
Reference in New Issue
Block a user