Unverified Commit e6fb48ce authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Fix string type on router.query (#7387)

parent dc1f907c
...@@ -5,6 +5,7 @@ import { parse } from 'url'; ...@@ -5,6 +5,7 @@ import { parse } from 'url';
import mitt, {MittEmitter} from '../mitt'; import mitt, {MittEmitter} from '../mitt';
import { formatWithValidation, getURL, loadGetInitialProps, NextPageContext, AppContextType } from '../utils'; import { formatWithValidation, getURL, loadGetInitialProps, NextPageContext, AppContextType } from '../utils';
import {rewriteUrlForNextExport} from './rewrite-url-for-export' import {rewriteUrlForNextExport} from './rewrite-url-for-export'
import { ParsedUrlQuery } from 'querystring';
function toRoute(path: string): string { function toRoute(path: string): string {
return path.replace(/\/$/, '') || '/' return path.replace(/\/$/, '') || '/'
...@@ -13,7 +14,7 @@ function toRoute(path: string): string { ...@@ -13,7 +14,7 @@ function toRoute(path: string): string {
export type BaseRouter = { export type BaseRouter = {
route: string route: string
pathname: string pathname: string
query: string query: ParsedUrlQuery
asPath: string, asPath: string,
} }
...@@ -31,7 +32,7 @@ type BeforePopStateCallback = (state: any) => boolean ...@@ -31,7 +32,7 @@ type BeforePopStateCallback = (state: any) => boolean
export default class Router implements BaseRouter { export default class Router implements BaseRouter {
route: string route: string
pathname: string pathname: string
query: string query: ParsedUrlQuery
asPath: string asPath: string
components: {[pathname: string]: RouteInfo} components: {[pathname: string]: RouteInfo}
subscriptions: Set<Subscription> subscriptions: Set<Subscription>
...@@ -41,7 +42,7 @@ export default class Router implements BaseRouter { ...@@ -41,7 +42,7 @@ export default class Router implements BaseRouter {
static events: MittEmitter = mitt() static events: MittEmitter = mitt()
constructor(pathname: string, query: any, as: string, { initialProps, pageLoader, App, Component, err }: {initialProps: any, pageLoader: any, Component: ComponentType, App: ComponentType, err?: Error}) { constructor(pathname: string, query: ParsedUrlQuery, as: string, { initialProps, pageLoader, App, Component, err }: {initialProps: any, pageLoader: any, Component: ComponentType, App: ComponentType, err?: Error}) {
// represents the current component key // represents the current component key
this.route = toRoute(pathname) this.route = toRoute(pathname)
......
...@@ -31,12 +31,12 @@ function noRouter() { ...@@ -31,12 +31,12 @@ function noRouter() {
class ServerRouter implements BaseRouter { class ServerRouter implements BaseRouter {
route: string route: string
pathname: string pathname: string
query: string query: ParsedUrlQuery
asPath: string asPath: string
// TODO: Remove in the next major version, as this would mean the user is adding event listeners in server-side `render` method // TODO: Remove in the next major version, as this would mean the user is adding event listeners in server-side `render` method
static events: MittEmitter = mitt() static events: MittEmitter = mitt()
constructor(pathname: string, query: any, as: string) { constructor(pathname: string, query: ParsedUrlQuery, as: string) {
this.route = pathname.replace(/\/$/, '') || '/' this.route = pathname.replace(/\/$/, '') || '/'
this.pathname = pathname this.pathname = pathname
this.query = query this.query = query
......
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