/src/routes.js
and add your new route to the routes
variable. The example below will result in the <NewPage />
element being called on the http://localhost:3000/pages/new
route.import DashboardLayout from "./layouts/Dashboard";
import NewPage from "./pages/NewPage";
const routes = [
{
path: "pages",
element: <DashboardLayout />,
children: [
{
path: "new",
element: <NewPage />,
},
],
},
];
export default routes;
import { Link } from "react-router-dom";
function ExampleComponent() {
return (
<Link to="pages/new">
New page
</Link>
);
}
export default ExampleComponent;
useNavigate
hook.import { useNavigate } from "react-router-dom";
function ExampleComponent() {
const navigate = useNavigate();
const handleSubmit = () => {
navigate("/pages/new");
};
return (
<form onSubmit={handleSubmit}>
...
</form>
);
}
export default ExampleComponent;