import * as R from 'ramda'; export const getQueryOfNextPageContext = (ctx: any) => { if (!ctx) { return {}; } const { pathname = '', asPath = '', query } = ctx; const routes = R.pipe( R.split('/'), R.filter((item: string) => /\[\w+\]/.test(item)), R.map((item: string) => R.replace(']', '', R.replace('[', '', item))), )(pathname); const path: any = R.pipe((R.split('#')) as unknown as any, R.slice(0, 1))(asPath) || []; const paths = path.length ? R.pipe( R.split('/'), R.filter((item: string) => item !== ''), )(path[0] as string) : []; const result = routes.map((key: string, index: number) => { return { [`${key}`]: paths[index], }; }); let newQuery: Record = {}; if (!routes.length) { newQuery.path = paths[0] || 'desktop'; } else { newQuery = R.mergeAll(result) || {}; } return { ...query, ...newQuery, }; };