未验证 提交 e6fb48ce 编写于 作者: J JJ Kasper 提交者: GitHub

Fix string type on router.query (#7387)

上级 dc1f907c
......@@ -5,6 +5,7 @@ import { parse } from 'url';
import mitt, {MittEmitter} from '../mitt';
import { formatWithValidation, getURL, loadGetInitialProps, NextPageContext, AppContextType } from '../utils';
import {rewriteUrlForNextExport} from './rewrite-url-for-export'
import { ParsedUrlQuery } from 'querystring';
function toRoute(path: string): string {
return path.replace(/\/$/, '') || '/'
......@@ -13,7 +14,7 @@ function toRoute(path: string): string {
export type BaseRouter = {
route: string
pathname: string
query: string
query: ParsedUrlQuery
asPath: string,
}
......@@ -31,7 +32,7 @@ type BeforePopStateCallback = (state: any) => boolean
export default class Router implements BaseRouter {
route: string
pathname: string
query: string
query: ParsedUrlQuery
asPath: string
components: {[pathname: string]: RouteInfo}
subscriptions: Set<Subscription>
......@@ -41,7 +42,7 @@ export default class Router implements BaseRouter {
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
this.route = toRoute(pathname)
......
......@@ -31,12 +31,12 @@ function noRouter() {
class ServerRouter implements BaseRouter {
route: string
pathname: string
query: string
query: ParsedUrlQuery
asPath: string
// 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()
constructor(pathname: string, query: any, as: string) {
constructor(pathname: string, query: ParsedUrlQuery, as: string) {
this.route = pathname.replace(/\/$/, '') || '/'
this.pathname = pathname
this.query = query
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册