1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00

Add <page>/index.html url re-writes to next/router.

This commit is contained in:
Arunoda Susiripala 2017-05-14 05:55:57 +05:30
parent c40ded0c12
commit 90991f176c

View file

@ -1,3 +1,5 @@
/* global __NEXT_DATA__ */
import { parse, format } from 'url' import { parse, format } from 'url'
import mitt from 'mitt' import mitt from 'mitt'
import shallowEquals from '../shallow-equals' import shallowEquals from '../shallow-equals'
@ -118,7 +120,17 @@ export default class Router {
// If url and as provided as an object representation, // If url and as provided as an object representation,
// we'll format them into the string version here. // we'll format them into the string version here.
const url = typeof _url === 'object' ? format(_url) : _url const url = typeof _url === 'object' ? format(_url) : _url
const as = typeof _as === 'object' ? format(_as) : _as let as = typeof _as === 'object' ? format(_as) : _as
// Add the ending slash to the paths. So, we can serve the
// "<page>/index.html" directly for the SSR page.
const asEndsWithSlash = /\/$/.test(as)
if (
__NEXT_DATA__.nextExport &&
!asEndsWithSlash
) {
as = `${as}/`
}
this.abortComponentLoad(as) this.abortComponentLoad(as)
const { pathname, query } = parse(url, true) const { pathname, query } = parse(url, true)