我有两种类型的路线,国家和内容:
- /国家
- /行业/排名
- /行业/观众
- /网站/排名
- /网站/观众
- /网站/转换
等等...
当用户进入应用程序时,我必须验证他是否已经选择了一个国家/地区,我正在使用localStorage保存该国家/地区。
如果用户已经选择了国家,他需要去/industry/ranking,如果没有,去/countries。
我收到有关通过代码更改路线的警告:
<Route> elements should not change from controlled to uncontrolled (or vice versa). You provided a "location" prop initially but omitted it on a subsequent render.
我的代码:
<Switch>
<Route exact path='/countries' component={Countries} />
{
current && (
<React.Fragment>
<Route exact path='/industry/ranking' render={() => <IndustryRanking country={current} />} />
<Route path='/industry/audience' render={() => <IndustryAudience country={current} />} />
<Route path='/website/ranking' render={() => <WebsiteRanking country={current} />} />
<Route path='/website/audience' render={() => <WebsiteAudience country={current} />} />
<Route path='/website/device' render={() => <WebsiteDevice country={current} />} />
<Route path='/website/conversion-orders' render={() => <WebsiteConversionOrders country={current} />} />
</React.Fragment>
)
}
{ !current ? <Redirect to='/countries' /> : <Redirect to='/industry/ranking' /> }
</Switch>
有没有办法仅使用路线来验证我的状况来改善这一点?
谢谢!