Created
July 20, 2020 04:08
-
-
Save Restoration/23fa309daefbd1b3397733e13b38c560 to your computer and use it in GitHub Desktop.
This file contains 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 React from 'react'; | |
import { withRouter } from 'next/router'; | |
// 型修正 | |
export const withComponentRouter = (Component: any) => { | |
return withRouter(({ router, ...props }) => { | |
// split at first `?` | |
const searchParams = new URLSearchParams(router.asPath.split(/\?/)[1]); | |
const query: { [key: string]: string } = {}; | |
// 型修正 | |
for (const [key, value] of searchParams as any) { | |
query[key] = value; | |
} | |
// replace the empty query | |
router.query = query; | |
return <Component {...props} router={router} />; | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment