I made some state in reducers that return a logged_in value that has a boolean value.
Here is my code:
import React from 'react' import { render } from 'react-dom' import { Router, Route, Link } from 'react-router' import { connect } from 'react-redux' export class NewStock extends React.Component { componentWillMount() { const { router, session } = this.props; if (session.userSessionData.get('logged_in') == false) { router.transitionTo('/login'); } }; render() { const { router, session } = this.props const currentRoute = router.location.pathname return ( <div className="row"> <h1>Hello World</h1> </div> ) } } function select(state) { return { router: state.router, flash: state.flash.get('newStock'), newStock: state.newStock, session: state.session } } export default connect(select)(NewStock)
This component is on the /new path
I want to check every time this page visits, it checks if logged_in true or false . if the user false is redirected to the /login page.
componentWillMount() { const { router, session } = this.props; if (session.userSessionData.get('logged_in') == false) { router.transitionTo('/login'); } };
But it returns an error that says:
Uncaught TypeError: router.transitionTo is not a function
Does anyone have the same problem? thank you in advance
source share