Skip to content

Commit

Permalink
fix: revert nextjs Routing behaviour but added hook to map as
Browse files Browse the repository at this point in the history
  • Loading branch information
BowlingX committed May 18, 2022
1 parent bd7bcaf commit b8c1b6e
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/lib/adapters/NextJs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ interface Props {
readonly asPath: string
readonly defaultPushOptions?: RouterOptions
readonly defaultReplaceOptions?: RouterOptions
// tslint:disable-next-line:no-mixed-interface
readonly createAsPath?: (queryParams: string) => string
}

export const GeschichteForNextjs: FC<Props> = ({
Expand All @@ -40,6 +42,7 @@ export const GeschichteForNextjs: FC<Props> = ({
Router,
defaultPushOptions,
defaultReplaceOptions,
createAsPath,
}) => {
const lastClientSideQuery = useRef(initialClientOnlyAsPath)
const historyInstance: HistoryManagement = useMemo(() => {
Expand All @@ -53,21 +56,23 @@ export const GeschichteForNextjs: FC<Props> = ({
},
push: (next: string, options) => {
const [path] = split(Router.asPath)
Router.push(`${path}${next}`, undefined, {
const nextAsPath = createAsPath ? createAsPath(next) : `${path}${next}`
Router.push(Router.route, nextAsPath, {
...defaultPushOptions,
...options,
})
},
replace: (next: string, options) => {
const [path] = split(Router.asPath)
Router.replace(`${path}${next}`, undefined, {
const nextAsPath = createAsPath ? createAsPath(next) : `${path}${next}`
Router.replace(Router.route, nextAsPath, {
...defaultReplaceOptions,
...options,
})
},
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [])
}, [createAsPath])

const useStore = useMemo(
() => useGeschichte(historyInstance),
Expand Down

0 comments on commit b8c1b6e

Please sign in to comment.