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
.
import React, {useState, useEffect } from "react";
...
const [ defaultRoute, setDefaultRoute ] = useState("/a");
...
useEffect( () => {}, [
...fetch api stuff...
if(isCustomer()) setDefaultRoute("/g");
]);
...
return (<div className="app">
<Switch>
<Route path="/a">
<A />
</Route>
<Route path="/c">
<C />
</Route>
<Route path="/b">
<B />
</Route>
<Route path="/">
<Redirect to={defaultRoute} />
</Route>
</Switch>
</div>);
Post a Comment for "Change Switch Main Path According To Api"