Questions tagged [react-router-v4]

React Router - A complete routing library for React inspired by Ember's routing system

Introduction

React Router is a powerful routing library built on top of React that helps you add new screens and flows to your application incredibly quickly, all while keeping the URL in sync with what's being displayed on the page.


Docs


Related tags

1988 questions
20
votes
6 answers

React Redux state is lost at page refresh

in my react app I have 3 components. from the 1st component by a button, I use Link to go to the 2nd component. at the 2nd I create a state (redux store), manipulate it and when manipulation is finished by submitting button I redirect to the 3rd…
Amir-Mousavi
  • 4,273
  • 12
  • 70
  • 123
20
votes
5 answers

React-Router 4 catch all route

My React routes are defined as follows: ... ... I want to…
James
  • 3,597
  • 11
  • 41
  • 76
20
votes
5 answers

How to preserve query parameters in react-router v4

Users redirected to my app after login (server on java), and they have url, which looks like this http://10.8.0.29:8083/html/?locale=RU&token=1c5c71f2-dcda-4a51-8cf6-f8f6ff1031d0&returnTo=http://10.8.0.23:8080/ (with some params, html - is folder…
Dmitry Malugin
  • 882
  • 1
  • 7
  • 25
19
votes
1 answer

React Router VS Conditional Rendering

I am confused about the core difference (especially regarding performance) between using React Router and regular conditional rendering approach. What I mean "regular conditional rendering approach" is, for example: we can set a state in parent…
Meow
  • 363
  • 4
  • 12
19
votes
3 answers

How can I get a variable from the path in react router?

My react router works fine.. but I would like get the date from the Path as the title which expects a string.
Embet Isit
  • 311
  • 1
  • 3
  • 12
19
votes
11 answers

How to use react-router 4.0 to refresh current route? not reload the whole page

'react-router-dom' has refresh function here, but I don't know how to call this method, also their well formatted document doesn't bother to explain this. window.location.reload() doesn't work for me, because it wipes out the app store as well. I…
Nicolas S.Xu
  • 13,794
  • 31
  • 84
  • 129
19
votes
1 answer

What's the Difference between the React Router v4 Router Types?

I have tried to learn some React basics on YouTube and from the official docs and I encountered multiple different Routers in only two videos. Sadly, the instructor did not explain anything at all and I'm even more confused than I was before. dr: I…
19
votes
3 answers

Is there a way to expose route params outside component?

If I have something like this: My routes config looks like: export default [{ path: '/', exact: true, main: Home }, { path: '/:someId', exact: true, main:…
19
votes
5 answers

Moving from react router 3.x to 4.x

How can I move to using https://cdnjs.cloudflare.com/ajax/libs/react-router/4.0.0-2/react-router.min.js from using https://cdnjs.cloudflare.com/ajax/libs/react-router/3.0.1/ReactRouter.min.js? Example using 3.x below. HTML
rich
  • 18,987
  • 11
  • 75
  • 101
18
votes
4 answers

React Hooks with React Router v4 - how do I redirect to another route?

I have a simple react hooks application - a list of Todos - with react router v4 On the List of Todos, when a Todo is clicked I need to: Dispatch the current todo in context Redirect to another route (from /todos to /todos/:id) In the previous…
WD1
  • 183
  • 1
  • 1
  • 4
18
votes
2 answers

How does one access state on a nested React component wrapped by an HOC?

I'm using Enzyme, and we can actually use the example component given in the docs as a foundation for my question. Let's assume this component uses a component from ReactRouter and thus we need to wrap it in a for…
indiesquidge
  • 781
  • 2
  • 8
  • 14
17
votes
3 answers

react router unmount function component

I am using React Router and have two routes that render the same component: This is Cmp implementation: class Cmp extends Component { …
Naor
  • 23,465
  • 48
  • 152
  • 268
17
votes
2 answers

Is it possible to have multiple in React.js?

I am building a React project without Redux. I would love to have two, or in this case 3 different Switches 1st Switch will be able to Switch between Home page (normal website) and UserPage (Dashboard) when user is logged in... Then each of this…
17
votes
2 answers

Get an active route with react-router in ReactJs

I am creating a project using reactjs.In my application i am getting the active route using this: this.context.router.isActive but getting undefined, i am using the react-router 4.Earlier this was worked for me when am using the lower version of…
Karan
  • 1,048
  • 2
  • 20
  • 38