wouter@3.7.1.patch 918 B

12345678910111213141516171819202122232425262728
  1. diff --git a/esm/index.js b/esm/index.js
  2. index c83bc63a2c10431fb62e25b7d490656a3796f301..bcae513cc20a4be6c38dc116e0b8d9bacda62b5b 100644
  3. --- a/esm/index.js
  4. +++ b/esm/index.js
  5. @@ -338,6 +338,23 @@ const Switch = ({ children, location }) => {
  6. const router = useRouter();
  7. const [originalLocation] = useLocationFromRouter(router);
  8. + // Collect all route paths to window object
  9. + if (typeof window !== 'undefined') {
  10. + if (!window.__WOUTER_ROUTES__) {
  11. + window.__WOUTER_ROUTES__ = [];
  12. + }
  13. +
  14. + const allChildren = flattenChildren(children);
  15. + allChildren.forEach((element) => {
  16. + if (isValidElement(element) && element.props.path) {
  17. + const path = element.props.path;
  18. + if (!window.__WOUTER_ROUTES__.includes(path)) {
  19. + window.__WOUTER_ROUTES__.push(path);
  20. + }
  21. + }
  22. + });
  23. + }
  24. +
  25. for (const element of flattenChildren(children)) {
  26. let match = 0;