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

Next 13 App Router Support (next/navigation) #103

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

scottrippey
Copy link
Owner

This PR adds support for Next 13's new App Router. It supplies functional mocks for the hooks in next/navigation.

TODO

  • Implement useRouter, usePathname, useParams, useSearchParams hooks
  • Add unit tests
  • lAdd the App Context Provider to the MemoryRouterProvider, for Storybook
  • Implement useSelectedLayoutSegment, useSelectedLayoutSegments hooks as noops
  • Consider how to implement API for mocking useSelectedLayoutSegment(s)
  • Consider how to implement mocks for other non-hook utils in next/navigation
  • Add new entry point, next-router-mock/navigation
  • Update docs

@changeset-bot
Copy link

changeset-bot bot commented Aug 15, 2023

🦋 Changeset detected

Latest commit: 8021d33

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
next-router-mock Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@kaufmann42
Copy link

Any idea when this might be completed? 😅

@italogama
Copy link

👀

@tkrotoff
Copy link

tkrotoff commented Oct 6, 2023

Beside the use* functions, next/navigation also provides:

@rob2d
Copy link

rob2d commented Nov 17, 2023

Since I was interested in using this library for mocking useRouter in Next13+, I briefly looked in to get tests passing on a commit if it helps:
next/navigation...rob2d:next-router-mock:next/navigation

Based on the check for the methods, it seemed the intention at least in one of the fixes was to simply wrap/reference the original singleton routers' instances.

Wouldn't mind chipping in but didn't want to do anything potentially redundant or unwanted since I'm not totally familiar with things. Is any specific help needed or wanted?

@SalahAdDin
Copy link

Is this package usable with NextJS 14?

@MarkLyck
Copy link

is this dead?

@SalahAdDin
Copy link

@scottrippey are you here?

@scottrippey
Copy link
Owner Author

I do not currently have the extra bandwidth to finish this PR, I'm sorry! I'd be happy to accept incoming PRs.

This PR is only partially complete. I've added support for the main 4 hooks, but there's still a lot of API methods that are not implemented. I'm willing to merge this as-is, since it will likely unblock many. However, the documentation is lacking, and the missing API methods would be frustrating.

Also I'd be happy to accept incoming PRs, if anyone wants to contribute!

@oleg-kuibar
Copy link

Perhaps someone will find this useful and will have time to dig into this.
Here is how storybook implemented their mocks for navigation: Link

@SalahAdDin
Copy link

Perhaps someone will find this useful and will have time to dig into this. Here is how storybook implemented their mocks for navigation: Link

So, we could use those mocks instead of this package, right?

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

Successfully merging this pull request may close these issues.

None yet

8 participants