joschan21 / breadit

Modern Fullstack Reddit Clone in Next.js 13 & TypeScript
1.06k stars 261 forks source link

Fix Modal Navigation #5

Open robharding opened 1 year ago

robharding commented 1 year ago

Hi Josh, thanks for the great tutorial. I was having issues getting the modals to behave as expected. To reproduce bring up the sign in modal, and then click the sign up button. If you try closing the sign out modal, it brings you back to the sign in modal instead of the expected page. My fix is to replace the page in the router instead of navigating.

robharding commented 1 year ago

forgot- both files will now need "use client"; on the first line because we are using the onClick hook.

robharding commented 1 year ago

This broke navigation when opening a modal from the sign up/sign in page, as closing the modal would take you to where you were before that page(not the page itself).

joschan21 commented 1 year ago

Awesome thanks for the PR, gonna look into it as soon as I find the time

robharding commented 1 year ago

Instead of onClick, the SignIn and SignUp can use the replace property to replace the current route in the case it's already on a modal.

JulianBristol commented 12 months ago

Thanks, works well!