Created
November 25, 2020 11:10
-
-
Save sibelius/d86641674909d51a5520590238b54a1b to your computer and use it in GitHub Desktop.
NextRouter Provider to be used on Storybook
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { RouterContext } from 'next/dist/next-server/lib/router-context' | |
| import Router from 'next/router' | |
| import React from 'react' | |
| Router.router = { | |
| route: '/', | |
| pathname: '/', | |
| query: {}, | |
| asPath: '/', | |
| push(url, as, options) { | |
| // action('nextRouter.push')(url, as, options); | |
| return Promise.resolve(true) | |
| }, | |
| replace(url, as, options) { | |
| // action('nextRouter.replace')(url, as, options); | |
| return Promise.resolve(true) | |
| }, | |
| reload() { | |
| // action('nextRouter.reload')(); | |
| }, | |
| back() { | |
| // action('nextRouter.back')(); | |
| }, | |
| prefetch(url, asPath, options) { | |
| // action('nextRouter.prefetch')(url, asPath, options); | |
| return Promise.resolve() | |
| }, | |
| beforePopState(cb) { | |
| // action('nextRouter.beforePopState')(cb); | |
| }, | |
| events: { | |
| on(type, handler) { | |
| // action('nextRouter.events.on')(type, handler); | |
| }, | |
| off(type, handler) { | |
| // action('nextRouter.events.off')(type, handler); | |
| }, | |
| emit(type) { | |
| // action('nextRouter.events.emit')(type); | |
| }, | |
| }, | |
| } | |
| export const StorybookNextRouter = ({ children }) => { | |
| return <RouterContext.Provider value={Router.router}>{children}</RouterContext.Provider> | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment