diff --git a/src/lib/adapters/NextJs.tsx b/src/lib/adapters/NextJs.tsx index 70ed5cc..b1f6cc4 100644 --- a/src/lib/adapters/NextJs.tsx +++ b/src/lib/adapters/NextJs.tsx @@ -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 = ({ @@ -40,6 +42,7 @@ export const GeschichteForNextjs: FC = ({ Router, defaultPushOptions, defaultReplaceOptions, + createAsPath, }) => { const lastClientSideQuery = useRef(initialClientOnlyAsPath) const historyInstance: HistoryManagement = useMemo(() => { @@ -53,21 +56,23 @@ export const GeschichteForNextjs: FC = ({ }, 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),