【发布时间】:2021-07-05 09:46:28
【问题描述】:
React(hooks)beginner here,当驱动程序或管理员访问网站时,它是这样的(示例): App.js:
<div className="app">
<Switch>
<Route path="/a">
<A />
</Route>
<Route path="/c">
<C />
</Route>
<Route path="/b">
<B />
</Route>
<Route path="/">
<Redirect to="/a" />
</Route>
</Switch>
</div>
如您所见,主路径是这样的: <Route path="/"> <Redirect to="/a" /> </Route>
这是我从 API 中得到的:
{ “id”:“2222”, “名称”:“随机2”, “isAdmin”:是的, “isDriver”:假, “是客户”:假, “公司”: { “id”:“11111”, “名称”:“随机”
} }
我的意思是如何改变主路径,例如如果“isCustomer”:true,那么主路径是< Route path="/"> <Redirect to="/g" /> </Route>
【问题讨论】:
-
这能回答你的问题吗? React Router Redirect Conditional
-
既然大家都说 Hooks 比较容易上手,我就从它开始,我不知道类是如何工作的
标签: javascript html reactjs routes react-router