Answer the question
In order to leave comments, you need to log in
Why is the component always rendered even if path = "*", react-router-dom?
Hello everyone, I would like to know why the react component is always rendered, although the path * is specified in the patch, and the url links to which do not exist. And how do I re-render to non-existent urls ? "react-router-dom": "^5.3.0"
Here is the code :
import s from "./App.module.css";
import routesConfig from "../../routes/routesConfig";
import { NavLink, Route, BrowserRouter, Switch } from "react-router-dom";
import Header from "@components/Header/Header";
import PersonPage from "../PersonPage/PersonPage";
import NotFoundPage from "../NotFoundPage/NotFoundPage";
const App = () => {
return (
<div className={s.wrapper}>
<BrowserRouter>
<Route component={Header} />
<Switch>
{routesConfig.map((route) => { // тут у нас массив с инофой для роутеров
return (
<Route
path={route.path}
exact={route.exact} // exact означает точное совпадение
component={route.component}
/>
);
})}
</Switch>
<Route path="*" exact component={NotFoundPage} />
</BrowserRouter>
</div>
);
};
export default App;
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question