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

05-prj-data-fetching useRouter Issue #48

Open
o-faro opened this issue Aug 22, 2023 · 1 comment
Open

05-prj-data-fetching useRouter Issue #48

o-faro opened this issue Aug 22, 2023 · 1 comment

Comments

@o-faro
Copy link

o-faro commented Aug 22, 2023

Hello, nice course, but there seems to be an issue with useRouter on pages/events/[...slug].js

Sometimes router.query.slug is an empty object and not only in pre-rendering phase. Especially wenn hitting enter instead of reloading the page.

To make sure not having any errors in my code I copied source code from your repo and changed the firebase url to my project.
I still get this error
image

I already did some research on this topic and tried to avoid this error by using 'router' Object in a useEffect without success. Using
useRouter().isReady as dependency did not work also. All in all quite unpredictable behaviour.

Also changed from "swr": "^2.2.1" to "swr": "^2.0.0" without success.
And also installed prj-05-data-fetching from this repository. Hitting enter a few times also leads to the described error.

@o-faro
Copy link
Author

o-faro commented Aug 25, 2023

In case somebody runs into the same issue, my workaround for this at the moment

 // so poor
  const router = useRouter();
  const filterData = router.query.slug;
  // ...
  const filterDate = !filterData
    ? window.location.pathname
      .replace('/events/', '')
      .split('/')
    : filterData;

  const filteredYear = filterDate[0];
  const filteredMonth = filterDate[1];

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

No branches or pull requests

1 participant