我尝试使用hookrouter而不是react-router,但我遇到了一个问题。我看到了一些类似问题的答案,但只针对react-router。而且,我最后只是复制粘贴了这段代码。
const routes = {
"/user": () => <Users />,
"/about": () => <About />,
"/contact": () => <Contact />
};
function App() {
const routeResult = useRoutes(routes);
return (
<div className="App">
<A href="/user">Users Page</A>
<A href="/about">About Page</A>
<A href="/contact">Contacts Page</A>
{routeResult}
</div>
);
}从这里开始,https://blog.logrocket.com/how-react-hooks-can-replace-react-router/,但是它不是那样工作的。我总是需要自己刷新页面,才能看到标题的变化。我怎么了? Upd: tag (而不是)正在正常工作
发布于 2021-06-23 22:54:15
如果您使用create,则必须删除标记在index.js中。
因此,在此之前:
ReactDOM.render(
<React.StrictMode>
<App />
</React.StrictMode>,
document.getElementById('root')
);及之后:
ReactDOM.render(<App />, document.getElementById("root"));https://stackoverflow.com/questions/64834248
复制相似问题