【问题标题】:Solidjs router does not renderSolidjs路由器不渲染
【发布时间】: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> 包装应用程序吗?

标签: routes solid-js


【解决方案1】:

该应用程序应包装在Router 组件中。

【讨论】:

    猜你喜欢
    • 2019-04-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-12
    • 2020-05-25
    • 2015-12-24
    • 2015-12-30
    相关资源
    最近更新 更多