Skip to content

Commit

Permalink
Expose addBasePath as router method
Browse files Browse the repository at this point in the history
  • Loading branch information
ijjk committed Jan 8, 2020
1 parent 34df1b7 commit 40fed59
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/next/client/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const coreMethodFields = [
'back',
'prefetch',
'beforePopState',
'addBasePath',
]

// Events is a static property on the router, the router doesn't have to be initialized to use it
Expand Down
2 changes: 2 additions & 0 deletions packages/next/next-server/lib/router/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ export default class Router implements BaseRouter {
}
}

addBasePath = addBasePath

onPopState = (e: PopStateEvent): void => {
if (!e.state) {
// We get state as undefined for two reasons.
Expand Down
4 changes: 3 additions & 1 deletion packages/next/next-server/server/render.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { IncomingMessage, ServerResponse } from 'http'
import { ParsedUrlQuery } from 'querystring'
import React from 'react'
import { renderToString, renderToStaticMarkup } from 'react-dom/server'
import { NextRouter } from '../lib/router/router'
import { NextRouter, addBasePath } from '../lib/router/router'
import mitt, { MittEmitter } from '../lib/mitt'
import {
loadGetInitialProps,
Expand Down Expand Up @@ -52,6 +52,7 @@ class ServerRouter implements NextRouter {
query: ParsedUrlQuery
asPath: string
events: any
addBasePath: typeof addBasePath
// 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()

Expand All @@ -60,6 +61,7 @@ class ServerRouter implements NextRouter {
this.pathname = pathname
this.query = query
this.asPath = as
this.addBasePath = addBasePath
}
push(): any {
noRouter()
Expand Down

0 comments on commit 40fed59

Please sign in to comment.