score:2
Accepted answer
use the exact prop in your home route.
<route exact path="/" component={home} />
score:1
i would add a <route>
component without providing path
that should redirect to 404
one.
try the following:
<switch>
<route exact path="/badges" component={badges} />
<route exact path="/badges/new" component={newbadge} />
<route path="/404" component={notfound} />
<route path="/" component={home} />
<route component={notfound} />
</switch>
i hope this helps!
score:1
i think you can do this:
<switch>
<route exact path="/badges" component={badges} />
<route exact path="/badges/new" component={newbadge} />
<route exact path="/" component={home} />
<route component={notfound} />
</switch>
Source: stackoverflow.com
Related Query
- Not found page and default home page always redirect to home - React Router
- React Router - Go back to the last page visited, and not the default component
- React Router - Open Link on new Tab and Redirect to Home Page
- How to redirect to not found page if slug doesn't exist using React Router Dom?
- My react router dom Redirect path is not working . Its not popping any error but is not making my home page to private Route
- React Router v4 - Redirect to home on page reload inside application
- React Router v4 redirect to current page and the component disappears
- React Router V4 - Route between components and not entire page
- Nested routes and not found route in react router dom v5
- My 404 not found page with React router is not working
- Show react router v4 not found page
- React Router Link with params not reloading page with new data from componentDidMount and Redux axios data fetching
- react router dom v6 doesnt redirect to not found
- Redirect to specific page if localstorage value not found in react
- React router not open 404 not found page
- How can handle not found page for nested routing in react router v4?
- 404 custom page not working with useContext and React Router
- React Router not found page showing up on all paths
- react router and routes is not working , i could not able to navigate to blogs page
- React router - click on card and redirect to a new page with content of that card (card details) using useParams and reacthooks
- React router - click on card and redirect to a new page with content of that card (card details)
- React router page redirect not correctly?
- use redirect path for signup but it not working. its redirect the home page and show a warning?
- In React Router Dom, redirect not work if i don't press enter or refresh page
- Page not found is displayed on all my pages - React Router
- Im using React Router and I want one of my route links with path="/" to be the home page on reload.. How can you do that?
- React Router not working and Warning: You tried to redirect to the same route you're currently on: "/"
- React Router URL not found if refresh page - Create React App
- Page Redirect not Working on Node Js and React JS on Simple Login Using Session
- React Router - root component is not removed and always stays on screen
More Query from same tag
- Configure gulp task to move files to subfolder
- Unhandled Rejection (Error) reducer is returning undefined
- React Testing with history passed
- React UseEffect is being calling twice
- React components make inheritance through Compositon
- What's the difference between `useCallback` with an empty array as inputs and `useCallback` without a second parameter?
- In what file do we connect react front end folder files with back-end folder files with server.js and mysql database connection?
- Why is onClick function call only passing one character? (ReactJs)
- Handling React onToggle event
- Is it possible to use react-router useHistory() or React useState with withFormik
- How to loop through and display buttons that have an onClick and pass a different variable to another function?
- Request body different from submitted data
- Cannot read properties of undefined (reading 'map') in reactjs fetch
- Sharing data between slice reducers when using createReducer
- React-Select onChange to store a value to pass to API call
- Reactjs RichTextEditor Custom Toolbar in .tsx
- How to add an interceptor to each request to keep ie from caching requests
- Reactjs - Accessing Post directly or hard refresh lead to blank page
- Mapping multiple Array in React.js
- react-bootstrap how to collapse menu when item is selected
- How to render conditionally with styled-components?
- Why mapStateToProps return empty object when state has been mutated?
- ReactJS: Nulled Object Are Still Being Called
- react-router <Link/> Wildcard Path Matching
- Why am I getting error TS2339 on querySelectorAll for checkbox property 'checked' does not exist
- How to test a React Component with Props in TypeScript using Jest?
- Unable to display blog comments on the browser in react js
- How can I export the type of an Action creators return value using Flow?
- Issue with useEffect dependency array
- React Component : "if else" statement not updating inside return statement