Answer the question
In order to leave comments, you need to log in
How to pass props when redirecting via React-Router?
There is a component with a push notification,
it should occur if the user wants to take a walk along private routes and will be returned to the main page via Redirect How to implement this? I so understood that it is impossible to transfer anything through Redirect.
Here, if you need a notification component (PopupNotification.jsx)
import React, {Component} from 'react';
import $ from 'jquery';
export default class PopupNotification extends Component{
componentDidMount(){
var notifyElement = $(".popup").addClass('active');
$('.popup').prepend(notifyElement);
setTimeout(function (ele) {
$(".popup").removeClass('active');
}, 3000, notifyElement);
}
render(){
return(
<div className="popup">
<i className="fa fa-exclamation-circle "></i>
<span className="popup_title">You must be logged in!</span>
</div>
)
}
}
import React from 'react';
import {Route, Redirect} from 'react-router-dom';
export default function PrivateRoute({user, component: Component, data, onLogout, ...rest}){
return(
<Route {...rest} render={
props=> (
user ?
<Component data={data} onLogout={onLogout}{...props} />
:
<Redirect to="/" />
)
} />
);
}
<PrivateRoute exact path="/videocourses" onLogout={this.logout} data={videoCoursesDB} user={this.state.user} component={VideoCourses}/>
Answer the question
In order to leave comments, you need to log in
Change state, on the main page, see what you have in state. Depends on what exactly in props you need on the main page.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question