I have two pages Page1 and Page2. I need to conditionally set either/or as the homepage based on a condition. I also need to ensure all urls are prefixed with an id. Take the following
<Routes>
<Route path={`/${id}`} element={condition ? <Page1 /> : <Page2>} />
<Route path={`/:id/page1`} element={<Page1 />} />
<Route path={`/:id/page2`} element={<Page2 />} />
<Route
path="/"
element={id
? <Navigate replace to={`/${id}`} />
: <Navigate replace to={`/`} />} />
}
/>
</Routes>
This sets the homepage url to '/123' and redirects to '/123' if the user enters '/'. I also have a condition on the first route which dynamically sets the component to render.
My issue is if 'condition' returns a promise then Page2 get set first and when condition is resolved swaps to Page1. Is there a better way to do this?