Skip to content
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]: [ProxyFacade] is not a <Route> component. All component children of <Routes> must be a <Route> or <React.Fragment] #8447

Closed
ErickSharp opened this issue Dec 6, 2021 · 7 comments
Labels

Comments

@ErickSharp
Copy link

ErickSharp commented Dec 6, 2021

What version of React Router are you using?

6

Steps to Reproduce

Code usage snippet below:
image

Expected Behavior

Seeing that all of the children of the < Routes > component are < Route >s, it should be working correctly and not raising an error.

Actual Behavior

Fails to work, saying that children should all be < Route >s when they already are.

@ErickSharp ErickSharp added the bug label Dec 6, 2021
@ErickSharp
Copy link
Author

Just downgraded to version 5, changed the Routes component to a Switch, and it is working perfectly... There is something wrong here...

@aksh05
Copy link

aksh05 commented Dec 6, 2021

@ErickSharp Are you using react hot loader in your app? The error seems related to that, because react hot loader wraps everything with proxies and hence you get the type of your function(Component) as [ProxyFacade], which leads to an error from react router as it verifies if there is anything other than Route or ReactFragment as children of Routes. Check here
You can either try removing hot loader first to verify if it is causing the issue or try fixing the hot loader issue as mentioned here.

PS: Above solution is only based on what you posted here. I might very well be wrong as I don't have all the details of your app configuration.

@ErickSharp
Copy link
Author

@ErickSharp Are you using react hot loader in your app? The error seems related to that, because react hot loader wraps everything with proxies and hence you get the type of your function(Component) as [ProxyFacade], which leads to an error from react router as it verifies if there is anything other than Route or ReactFragment as children of Routes. Check here

You can either try removing hot loader first to verify if it is causing the issue or try fixing the hot loader issue as mentioned here.

PS: Above solution is only based on what you posted here. I might very well be wrong as I don't have all the details of your app configuration.

Yes, you are correct. I am using a hot-loader inside of an electron app. I will try the fix that you mentioned above and report back in this thread.

@johnhillphoto
Copy link

Would it be possible to add some kind of configuration option to disable this invariant error? Our app works perfectly in production, but we cannot use react-hot-loader now. Our app worked well with v6.0.0 also.

@timdorr
Copy link
Member

timdorr commented Dec 6, 2021

You need to move those components into the element prop.

@timdorr timdorr closed this as completed Dec 6, 2021
@aksh05
Copy link

aksh05 commented Dec 7, 2021

Thanks @timdorr, I forgot to mention that element prop should be added as well. But I still think @ErickSharp has to fix the hot loader issue in order to completely resolve the error, because RHL is anyways going to wrap the components with proxies and the same issue would occur again even after adding the element prop.

@john-kamau01
Copy link

Hello,

I think the solution to the code is to wrap the routes in a 'Routes'.

<Routes> <Route path='/' element={} /> <Route path='/path-2' element={} /> </Routes>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants