Here is my code
const AppRoutes: FC = () => {
const {currentUser, fetchingAuth} = useAuth()
let route
if (fetchingAuth || !currentUser) {
route = <Route path='*' element={null}></Route>
} else {
route = (
<>
<Route path='/' element={<OptInPage />} />
</>
)
}
return (
<MemoryRouter>
<Routes>{route}</Routes>
</MemoryRouter>
)
}
OptInPage
const OptInPage = () => (
<Routes>
<Route element={<OptInLayout />}>
<Route path='opt-in' element={<OptIn />} />
<Route path='get-items' element={<GetItems />} />
<Route index element={<OptIn />} />
</Route>
</Routes>
)
When I try to navigate to /get-items, the route is not found, however when I change AppRoutes to be the following
const AppRoutes: FC = () => {
const {currentUser, fetchingAuth} = useAuth()
let route
if (fetchingAuth || !currentUser) {
route = <Route path='*' element={null}></Route>
} else {
route = (
<Route element={<OptInLayout />}>
<Route path='opt-in' element={<OptIn />} />
<Route path='get-connections' element={<GetConnections />} />
<Route index element={<OptIn />} />
</Route>
)
}
return (
<MemoryRouter>
<Routes>{route}</Routes>
</MemoryRouter>
)
}
It does work, am I missing something? how come when the component is nested, the route is not found