Unverified Commit 21fae526 authored by Joe Haddad's avatar Joe Haddad Committed by GitHub

Reuse router logic instead of duping in client (#7476)

parent 06e0befd
......@@ -13,6 +13,7 @@ import {
NextPageContext,
} from '../utils'
import { rewriteUrlForNextExport } from './rewrite-url-for-export'
import { getRouteMatcher } from './utils/route-matcher'
import { getRouteRegex } from './utils/route-regex'
function toRoute(path: string): string {
......@@ -270,8 +271,8 @@ export default class Router implements BaseRouter {
// detect dynamic routing
if (route.indexOf('/$') !== -1) {
const { re: routeRegex, groups } = getRouteRegex(route)
const routeMatch = routeRegex.exec(as)
const rr = getRouteRegex(route)
const routeMatch = getRouteMatcher(rr)(as)
if (!routeMatch) {
console.error(
"Your `<Link>`'s `as` value is incompatible with the `href` value. This is invalid."
......@@ -279,12 +280,8 @@ export default class Router implements BaseRouter {
return resolve(false)
}
Object.keys(groups).forEach(slugName => {
const m = routeMatch[groups[slugName]]
if (m !== undefined) {
query[slugName] = decodeURIComponent(m)
}
})
// Merge params into `query`, overwriting any specified in search
Object.assign(query, routeMatch)
}
Router.events.emit('routeChangeStart', as)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment