Commit b18ecc92 authored by Arunoda Susiripala's avatar Arunoda Susiripala

Implement client side routing as they should work.

Basicaly, now client side routing as they work like
in Next.js including prefetching.
parent 2796c08e
......@@ -40,10 +40,6 @@ export default class Link extends Component {
return
}
if (__NEXT_DATA__.nextExport) {
return
}
let { href, as } = this
if (!isLocal(href)) {
......@@ -79,7 +75,6 @@ export default class Link extends Component {
}
prefetch () {
if (__NEXT_DATA__.nextExport) return
if (!this.props.prefetch) return
if (typeof window === 'undefined') return
......
/* global window, document */
/* global window, document, __NEXT_DATA__ */
import mitt from 'mitt'
const webpackModule = module
......@@ -65,6 +65,10 @@ export default class PageLoader {
loadScript (route) {
route = this.normalizeRoute(route)
if (__NEXT_DATA__.nextExport) {
route = route === '/' ? '/index.js' : `${route}/index.js`
}
const script = document.createElement('script')
const url = `${this.assetPrefix}/_next/${encodeURIComponent(this.buildId)}/page${route}`
script.src = url
......
/* global __NEXT_DATA__ */
import { parse, format } from 'url'
import mitt from 'mitt'
import shallowEquals from '../shallow-equals'
......@@ -121,16 +120,6 @@ export default class Router {
const url = typeof _url === 'object' ? format(_url) : _url
const as = typeof _as === 'object' ? format(_as) : _as
// We need to load the page via SSR everytime if we
// are in the nextExport mode.
if (__NEXT_DATA__.nextExport) {
// Add the ending slash to the paths. So, we can serve the
// "<page>/index.html" directly.
const endsWithSlash = /\/$/.test(as)
window.location.href = endsWithSlash ? as : `${as}/`
return
}
this.abortComponentLoad(as)
const { pathname, query } = parse(url, true)
......@@ -278,7 +267,6 @@ export default class Router {
}
async prefetch (url) {
if (__NEXT_DATA__.nextExport) return
// We don't add support for prefetch in the development mode.
// If we do that, our on-demand-entries optimization won't performs better
if (process.env.NODE_ENV === 'development') return
......
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