У меня есть два типа маршрутов, стран и контента:
- / страны
- / индустрия / рейтинг
- / индустрия / аудитория
- / веб-сайт / рейтинг
- / веб-сайт / аудитория
- / веб-сайт / конверсия
и т. д. *
Когда пользователь входит в приложениеЯ должен проверить, выбрал ли он уже страну, которую я сохраняю, используя localStorage .
Если у пользователя уже выбрана страна, ему нужно перейти на /промышленность / рейтинг , если нет - / страны .
Я получаю предупреждение об изменении маршрута с помощью кода:
<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>
Есть ли способ улучшить это, используя только маршруты для проверки моего состояния?
Спасибо!