New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[bug]: Custom route components do not render #8111
Comments
I just tried each version of the beta's. It was working up to version 3. It is now broken in v4 + |
Routes are statically analyzed for their props, but not actually rendered so your routes up there w/o a You can get the same effect by using normal components instead of Routes. Since const SwitchElement = ({ a, b }) => {
const someExternalStateBool = true;
if (someExternalStateBool) {
return a;
} else {
return b;
}
};
export default function App() {
return (
<BrowserRouter>
<Routes>
<Route path="/" element={<span>root</span>} />
<Route
path="/test"
element={<SwitchElement a={<span>A</span>} b={<span>B</span>} />}
/>
</Routes>
</BrowserRouter>
);
} |
Co-authored-by: Mark Dalgleish <mark.john.dalgleish@gmail.com>
What version of React Router are you using?
v6 - beta.5
Steps to Reproduce
I have a Routes that has two routes,
/
and/test
. However the test route is in a custom component that returns a route based on external state.This was working in
beta.0
I have not tested the versions in between to find the changed version yet.https://codesandbox.io/s/keen-snyder-npoeq?file=/src/App.tsx:181-716
Expected Behavior
I would expect the
SwitchRoute
to render and return a route.Actual Behavior
In this case the
SwitchRoute
isn't even being rendered. The console.log is not ran and the component does not show up in the tree.I use custom routes like this and authenticated routes where auth is checked before the route is processed further.
The text was updated successfully, but these errors were encountered: