1
 <div>
               <Switch>
                    <Route path="/login" component={Login}/>
                    <Route path="/signup" component={Register}/>
                    <Route path="/profile" component={Profile}/>
                    <Route path="/resetpassword" component={ResetPassword}/>
                    <Route path="/forgotpassword" component={ForgotPassword}/>
                    <PrivateRoute path="/" component={Feed}/>
                    <Route path="*" component={Error}/>
               </Switch>
            </div>
import React, { Component } from 'react';
import {Route,Redirect} from "react-router-dom";


const PrivateRoute = ({component:Component, ...rest}) => (
    <Route {...rest} render={(props) => (
         props.user? 
        <Component {...props}/> : 
        <Redirect to="/login"/>
    )}/>
);


export default PrivateRoute;

So every route is working, except from when I type a url that doesn't exist. Whenever I do that, then it redirects me to the login page. Is there a way to stop the PrivateRoute from preventing the auto redirect when a page is not found?

thanks in advance for all the help!!

1 Answers1

0

You can try with exact path

   <Switch>
       <Route path="/login" component={Login}/>
       <Route path="/signup" component={Register}/>
       <Route path="/profile" component={Profile}/>
       <Route path="/resetpassword" component={ResetPassword}/>
       <Route path="/forgotpassword" component={ForgotPassword}/>
       <PrivateRoute exact path="/" component={Feed}/>
       <Route path="*" component={Error}/>
   </Switch>
ppichier
  • 815
  • 1
  • 7
  • 18