Supported cryptocurrencies:
BCH Bitcoin Cash
0.0001 BCH
EnglishNeed help to better understand the protected route on React

Hello all, can anyone explain me these 3 lines on the code? line 5: component: Component, ... rest line 8 {} line 9 props line 11 as I understand is the user properties. Protected Route are used as a way for an authorized user to get access to a component. For example Members area.

godzilla34 1 month ago
  • Code
  • React
  • Programming

kimo2 1 month ago
kimo2 1 month ago Correct
Well, let's say you have a such route:
<ProtectedRoute path="/private" component={PrivateArea} />

So, when the above component is called, this happens:

line 5:
var Component = PrivateArea
var rest = *remaining properties*
you can add console.log(Component); console.log(rest); between line 5 and 6 to check it

line 8:
'rest' is passed to Route, so ProtectedRoute works as a wrapper for Route component.

line 9: standard rendering routine for Route component
props is an object, which contains Route component attributes, including those, which were passed through 'rest' var.
Add 'console.log(props);' before if-statement.

line 11:
call PrivateArea component (because Component=PrivateArea)
godzilla34 1 month ago
Great explanation. Thank you.
Ahmad 1 month ago
Refugees in tents are in dire need of aid
test 1 month ago
Ahmad 1 month ago
Refugees in tents are in dire need of aid