L
L
lavezzi12018-09-11 20:16:49
JavaScript
lavezzi1, 2018-09-11 20:16:49

How to pull api when switching to certain routes to check authorization?

Hello. There is a backend on express and rest api. Authorization by JWT. Studying the react dock and its router, I found an example of how to make a private route, everything is fine, but I'm interested in the possibility of calling a request for a user profile every time I go to routes that require authorization.
To give an analogy, in Vue.js this is done in 2 seconds by using the beforeEach() router hook.
How to do this in react? Thank you.

Answer the question

In order to leave comments, you need to log in

5 answer(s)
M
Maxim, 2018-09-11
@maxfarseer

react-router v3 had such an onEnter hook, version 4 does not have it.
In the PrivateRouter component, add a check for new props (using getDerivedStateFromProps or componentWillReceiveProps [deprecated]), where you look - if the route (from match ) has changed - make a request to the API.
If you use a reach router, then you don't know. Didn't watch it.

S
Sasha Misnik, 2015-03-21
@Razorvin

try like this

position:absolute;
left:50%;

A
Alexander Taratin, 2015-03-21
@Taraflex

habrahabr.ru/post/189696

K
keslo, 2015-03-21
@keslo

What is the positioning of the parent?
And best of all the source in the studio.

A
Alim Alibaev, 2015-03-21
@a4gg

margin: 0 auto; only works when you set the width

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question