Skip to content Skip to sidebar Skip to footer

Change Switch Main Path According To Api

React(hooks)beginner here, at the moment when driver or admin goes to website it is like this(example): App.js: As you can see main path is this :

Solution 1:

Totally untested but my hunch is something along the lines of:

Use useState to hold the default route and update the default route if the result of your api call says it's a customer. Pass the state to the Redirect.

importReact, {useState, useEffect } from"react";

...

const [ defaultRoute, setDefaultRoute ] = useState("/a");

...

useEffect( () => {}, [
  ...fetch api stuff...
  
  if(isCustomer()) setDefaultRoute("/g");
]);

...

return (<divclassName="app"><Switch><Routepath="/a"><A /></Route><Routepath="/c"><C /></Route><Routepath="/b"><B /></Route><Routepath="/"><Redirectto={defaultRoute} /></Route></Switch></div>);

Post a Comment for "Change Switch Main Path According To Api"