【发布时间】:2022-09-28 02:25:13
【问题描述】:
我已经搜索了很多并且找不到答案,在我的 SolidJs 应用程序中,第二条路线没有在根元素中重新定义:
import { Routes, Route, useLocation } from \"solid-app-router\"
import { useNavigate } from \'solid-app-router\';
const Login = lazy(() => import(\"./pages/login\"));
const Operation = lazy(() => import(\"./pages/operation\"));
export default function App() {
const navigate = useNavigate();
const location = useLocation();
onMount(() => {
const token = localStorage.getItem(\'token\');
if (!token && location.pathname !== \'/\') {
navigate(\"/\", { replace: true });
}
if (token && location.pathname === \'/\') {
navigate(\"/operations\", { replace: true });
}
});
return (
<Routes>
<Route path=\'/\' component={Login} />
<Route path=\'/operations\' component={Operation} />
</Routes>
)
}
Everything it looks ok at component Operation and if i call this component in first route like bellow it work:
<Route path=\'/\' component={Operation} />```
-
只是检查你有 <Router> 包装应用程序吗?