I'm facing the ReactJS routing issue. Working Demo. I'm using the hookrouter
package.
Issue:
As mentioned in the demo, if I'm on the /users
route and when I click on about
link, the URL changes but About
Component is not getting loaded.
What I want?
Is there a way to load a Component when I click on its link?
import { A, useRoutes } from "hookrouter";
const Users = () => {
return (
<div>
<h1>Users</h1>
<A href="/about">About</A>
</div>
);
};
const About = () => {
return (
<div>
<h1>About</h1>
<A href="/users">Users</A>
</div>
);
};
const routes = {
"/users": () => <Users />,
"/about": () => <About />
};
function App() {
const routeResult = useRoutes(routes);
return (
<div className="App">
<div>
<A href="/users">Users Page</A>
</div>
<div>
<A href="/about">About Page</A>
</div>
{routeResult}
</div>
);
}
const rootElement = document.getElementById("root");
ReactDOM.render(<React.StrictMode><App /></React.StrictMode>, rootElement);