I'm using zustand in a project with Nextjs and have an issue with next/router. Currently with my zustand setup I cannot destructure router from useRouter so I'm importing the Router object directly to use Router.push after fetching some data. This worked in every project I've created up until using the app directory, is there a solution to this?
// my zustand store
import Router from 'next/router'
import create from 'zustand'
const store = (set, get) => ({
// some state
// some actions
startGame: async () => {
// fetch some data then navigate
Router.push('/gamePage')
},
})
const useStore = create(store)
export default useStore;
It produces the error:
Error: No router instance found. You should only use "next/router" on the client side of your app.
To navigate to '/gamePage'