Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

React Router rendering blank pages for all components

<Switch>
  <Route
    path="/login"
    render={props => !isAuthenticated
      ? (
        <Login setAuth={setAuth} {...props} />
      ) : (
        <Redirect to="/dashboard" />
      )     
    }
  />
  <Route
    path="/register"
    render={props => !isAuthenticated
      ? (
        <Register setAuth={setAuth} {...props} />
      ) : (
        <Redirect to="/dashboard" />
      )
    }
  />
  <Route
    path="/dashboard"
    render={props => isAuthenticated
      ? (
        <Dashboard setAuth={setAuth} {...props} />
      ) : (
        <Redirect to="/login" />
      )
    }
  />
</Switch>

//update

const [isAuthenticated, setIsAuthenticated] = useState();

if (isAuthenticated === undefined) {
  return null; // or loading spinner, etc...
}

return (
  ... routes & UI ...
);
Comment

PREVIOUS NEXT
Code Example
Javascript :: infinite typing effect react 
Javascript :: Javascript - Dependency between arguments of partial applications 
Javascript :: Javascript shows me TypeError saying my variable is undefined 
Javascript :: how to setup a webpack quickly 
Javascript :: Examples of correct code for the { "typeof": true } option with global declaration: 
Javascript :: getting json from response using getSync method 
Javascript :: Why is the return function in my debounce function never called? Angularjs 
Javascript :: How to append variable with anchor element href link in Angularjs 
Javascript :: angularjs trying to fix a rack lint error and 500 on GET /cable 
Javascript :: How to call keyup function on textbox for every dynamic generated form in Angular8 
Javascript :: Porting Promise.all functionality from AngularJs to VueJs 
Javascript :: List of data with buttons that should display the rest of the data below 
Javascript :: Display all posts from database 
Javascript :: .push( ) is not updating the variable 
Javascript :: coin gecko api 
Javascript :: setup app files in node js 
Javascript :: Special Chars like DOTS in Express.js route 
Javascript :: aws amplify react site is blank after updating react-router-dom 
Javascript :: mustache tutorial javascript 
Javascript :: word array to string cryptojs 
Javascript :: phaser reverse matrix rows 
Javascript :: Adding Proof of Work to blockchain 
Javascript :: React Using Self Made Module 
Javascript :: append vs appendchild 
Javascript :: js how to get random number (inclusive min max) and push it in an array 
Javascript :: An Array Of Functions With Parameter 
Javascript :: aws cognito user pool and angular 
Javascript :: javascript check if array has at least one true value 
Javascript :: useEffect : react to manipulate the DOM 
Javascript :: angular file upload code anji 
ADD CONTENT
Topic
Content
Source link
Name
8+9 =