R
R
real22102019-03-12 08:58:37
React
real2210, 2019-03-12 08:58:37

What is the best way to check if a react-routerv4 route is correct?

there is such a route: 'somepath/:id/:page'
As usual, for example, the id parameter is checked for the fact that it belongs to the user.
Now my access to somepath is limited by the private router, and the check that the user's id is not equal to :id is in did mount.
But I don't really like the idea of ​​did mount with
react-redux

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Demian Smith, 2019-03-12
@search

Here is an article just about this https://tylermcginnis.com/react-router-protected-r...
You make a PrivateRoute component (in your case it can be called differently, for example PrivatePageRoute) and check in it whether it is possible or not. And if not, then show an error message or output <Redirect to={...}>to redirect to the right place.

V
Viktor Taran, 2016-11-10
@denisbookreev

everything is easy

реврайт конд   реквест ури ^(flowers.)(*)&
реврайт рул http://syte.ru/%2

Parentheses from the conda to pass to the rule,
they are not passed $1 $2 A %1 %2
Actually, you choose the condition and in brackets you spread the necessary and unnecessary parts,
the number is the number of the bracket.
Just do not forget that all that for "?"
it is a get and is not part of the string!!!!
All get requests are redirected separately

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question