score:2
Actually, it is ok to use this type of private route in react, but you should check two moments:
I should check, that you do not have
exact
attribute, so all your routes like/dashboard/panel1
,/dashboard/panel2
will be private toauth.isAuthenticated} path="/dashboard" component={Dashboard} />
You will have some problem with connect. There is a simple fix for that:
export default connect(mapStateToProps, null, null, { pure: false, })(PrivateRoute);
more information here: React router private routes / redirect not working
Source: stackoverflow.com
Related Query
- React router v4 with redux protected routes and auth
- Protected Routes React Router 4 not working with auth state stored in Redux
- Refresh on protected Routes React Router with firebase auth
- React Redux with hooks - authentication and protected routes
- React Router V4 protected private route with Redux-persist and React-snapshot
- onEnter Transitions with React Router and Redux Simple Router Dont Render New Route's Component
- Sync queryParameters with Redux state and react router for function components
- How to test React Router params with Redux and enzyme
- How to add login authentication and session to ReactJS React Router and Redux with MongoDB + NodeJS Express?
- Auth Protected Routes React Router V4 - Passing Props
- React with Redux and Router - server rendering
- what is the best way to use react router V6 navigation with redux and redux thunk actions?
- How Mapping Routes in React Router with Protected Function?
- React Router and redux auth token double render
- React Redux with Router Location, Pagination / Sorting and Fetch
- How to route correctly with a mixture of parent and child routes with React Router
- React Router Link with params not reloading page with new data from componentDidMount and Redux axios data fetching
- React router NavLink activeClassName does not work with redux and styled components
- React router protected route with firebase auth check
- Building a dynamic nested routes architechure with React and React Router
- How to properly set property(if user is logged) from cookie after page opens or F5 in React with router and redux
- react router and redux dispatch() is running from all routes once instead of only current route
- form using React hook form and redux toolkit. then routes in react router dom
- Global popup in React with Router and Redux
- Protect routes with React Router v6 and API Call
- Private Route with Redux and react router
- Using React Router with Switch and can't get the page to render different components when changing routes
- How to add Nested and Non-Nested Routes with React Router - ReactJS?
- Nested Match routes with React Router v4 and MatchWithFade
- Create custom dynamic routes with react router and regex to the same component
More Query from same tag
- How to push data from backend to frontend in react
- How to use Refs with Material-ui 4, React 16.8, TypeScript 3.5
- Prevent keys that are not the enter key from triggering submit function
- Change the input text file in react
- How to map an array in order to change it?
- Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: symbol
- React-select clears the value (state) of the other input fields when select option is changed (onChange)
- How to configure jest config to use aliases like in storybook config?
- Ant Design v4 Card Style boxShadow
- Errors When Transpiling React Project With Babel
- How select part of text in a Textfield on onFocus event with material-UI in React?
- Get all the selected options on each onChange event
- how to make looping in the React state?
- How to create markers on click of geojson component?
- how could I specify a type for a react component in typescript?
- ReactJS: "this.props" is not a function when child component calls parent
- Return promise from React Redux Thunk
- How can I use 'this' in defaultProps React.Component class syntax?
- How to solve double API fetch on universal ReactJS
- Is there a way to check propTypes for observer(Component)
- React GraphQL - How to return the results of a Query component as an object to use in React context
- React onItemClick not triggering single item after mapping
- Initial static React HTML rendering with Webpack
- group array with timestamps
- Material ui Component "Select" does not set the chosen item. Selected item doesn't stay selected, and it renders very small
- why are my rows and columns slightly to the left with react-bootstrap?
- how do I make a math Django and react web application?
- react-select doesn't keep indexes on manipulated arrays
- MSAL authentication and authorization from React to Web API
- Passing a props to Functional Component in route ReactJs