Skip to content

Commit

Permalink
add basepath
Browse files Browse the repository at this point in the history
  • Loading branch information
Janpot committed Jul 20, 2020
1 parent faeca86 commit 31d000e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
2 changes: 2 additions & 0 deletions docs/api-reference/next/router.md
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,8 @@ You can listen to different events happening inside the Next.js Router. Here's a
- `hashChangeComplete(url)` - Fires when the hash has changed but not the page

> Here `url` is the URL shown in the browser. If you call `router.push(url, as)` (or similar), then the value of `url` will be `as`.
>
> **Note:** If you [configure a `basePath`](/docs/api-reference/next.config.js/basepath.md) then the value of `url` will be `basePath + as`.
#### Usage

Expand Down
14 changes: 7 additions & 7 deletions packages/next/next-server/lib/router/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ export default class Router implements BaseRouter {
}

const cleanedAs = delBasePath(as)
this._inFlightRoute = cleanedAs
this._inFlightRoute = as

// If the url change is only related to a hash change
// We should not proceed. We should only change the state.
Expand All @@ -461,10 +461,10 @@ export default class Router implements BaseRouter {
// any time without notice.
if (!options._h && this.onlyAHashChange(cleanedAs)) {
this.asPath = cleanedAs
Router.events.emit('hashChangeStart', cleanedAs)
Router.events.emit('hashChangeStart', as)
this.changeState(method, url, as, options)
this.scrollToHash(cleanedAs)
Router.events.emit('hashChangeComplete', cleanedAs)
Router.events.emit('hashChangeComplete', as)
return true
}

Expand Down Expand Up @@ -524,7 +524,7 @@ export default class Router implements BaseRouter {
}
}

Router.events.emit('routeChangeStart', cleanedAs)
Router.events.emit('routeChangeStart', as)

// If shallow is true and the route exists in the router cache we reuse the previous result
return this.getRouteInfo(route, pathname, query, as, shallow).then(
Expand All @@ -537,11 +537,11 @@ export default class Router implements BaseRouter {
}

if (error && error[ABORTED]) {
Router.events.emit('routeChangeError', error, cleanedAs)
Router.events.emit('routeChangeError', error, as)
return false
}

Router.events.emit('beforeHistoryChange', cleanedAs)
Router.events.emit('beforeHistoryChange', as)
this.changeState(method, url, as, options)

if (process.env.NODE_ENV !== 'production') {
Expand All @@ -563,7 +563,7 @@ export default class Router implements BaseRouter {
window.scrollTo(options._N_X, options._N_Y)
}
}
Router.events.emit('routeChangeComplete', cleanedAs)
Router.events.emit('routeChangeComplete', as)

return true
}
Expand Down

0 comments on commit 31d000e

Please sign in to comment.