mirror of
https://github.com/terribleplan/next.js.git
synced 2024-01-19 02:48:18 +00:00
Implement client side routing as they should work.
Basicaly, now client side routing as they work like in Next.js including prefetching.
This commit is contained in:
parent
2796c08ef7
commit
b18ecc925b
|
@ -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
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* 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
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
/* 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
|
||||
|
|
Loading…
Reference in a new issue