gpt4 book ai didi

solid-js - Solid App Router 元素不是渲染组件 - 对象对象

转载 作者:行者123 更新时间:2023-12-03 08:05:10 27 4
gpt4 key购买 nike

刚开始使用SolidJS和固体路由器,已经卡在路线上,没有渲染“元素”内的组件。相反,它显示“[object Object][object Object]”

enter image description here

参见: https://codesandbox.io/s/solidjs-shopping-cart-wj5zvr?file=/src/App.jsx

下面是代码:

import { Router, Route } from "solid-app-router";

function Home() {
return <h1>Home page here...</h1>;
}
function Cart() {
return <h1>Cart page here...</h1>;
}

function App() {
return (
<>
<header>header...</header>
<Router>
<Route path="/" element={<Home />} />
<Route path="/cart" element={<Cart />} />
</Router>
<footer>footer..</footer>
</>
);
}

export default App;

最佳答案

尝试使用<Route path="/" component={Home} />相反。

这也使得将来转换为惰性路由(用于代码分割)变得很浪费......

<Route path="/" component={lazy(() => import("./home"))} />

编辑:我查看了你的codesandbox,发现已经有了 <Router>index.jsx那么你想要 App.jsx 中的内容实际上是<Routes>...<Routes> .

      <Routes>
<Route path="/" component={Home} />
<Route path="/cart" component={Cart} />
</Routes>

关于solid-js - Solid App Router 元素不是渲染组件 - 对象对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72589015/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com