Skip to content
This repository was archived by the owner on Nov 8, 2022. It is now read-only.

Commit a17fb84

Browse files
committed
fix(route): use history.pushState intead of next build-in
1 parent afc09a4 commit a17fb84

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

containers/Route/logic.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useEffect } from 'react'
2-
import { buildLog, getMainPath, getSubPath, Global } from '@utils'
2+
import { Global, buildLog, getMainPath, getSubPath } from '@utils'
33

44
/* eslint-disable-next-line */
55
const log = buildLog('L:Route')
@@ -12,6 +12,9 @@ const browserHistoryBtnClicked = popstate => {
1212
Global.location = popstate.state.as
1313
}
1414

15+
// ###############################
16+
// init & uninit
17+
// ###############################
1518
export const init = (_store, routeObj) => {
1619
if (store) return false
1720

@@ -28,10 +31,6 @@ export const init = (_store, routeObj) => {
2831

2932
export const uninit = () => {}
3033

31-
// ###############################
32-
// init & uninit
33-
// ###############################
34-
3534
export const useInit = (_store, routeObj) => {
3635
useEffect(() => {
3736
store = _store
@@ -45,5 +44,3 @@ export const useInit = (_store, routeObj) => {
4544
Global.onpopstate = browserHistoryBtnClicked
4645
}, [_store, routeObj])
4746
}
48-
49-
export const holder = 1

containers/Route/store.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55

66
import { types as t, getParent } from 'mobx-state-tree'
77
import R from 'ramda'
8-
import Router from 'next/router'
8+
// import Router from 'next/router'
99

1010
import { PAGE_SIZE } from '@config'
11-
import { onClient, markStates, buildLog, serializeQuery } from '@utils'
11+
import { Global, onClient, markStates, buildLog, serializeQuery } from '@utils'
1212

1313
/* eslint-disable-next-line */
1414
const log = buildLog('S:RouteStore')
@@ -47,18 +47,20 @@ const RouteStore = t
4747

4848
if (page && String(page) === '1') query = R.omit(['page'], query)
4949

50-
const allQueryString = serializeQuery(query)
50+
// const allQueryString = serializeQuery(query)
5151
const queryString = serializeQuery(R.omit(['mainPath', 'subPath'], query))
5252

53-
const url = `/${allQueryString}`
53+
// const url = `/${allQueryString}`
5454
const asPath = `/${self.mainPath}/${self.subPath}${queryString}`
5555

5656
// NOTE: shallow option only works for same page url
5757
// if page is diffrent, it will cause page reload
5858
/* console.log('push url: ', url) */
59-
Router.push(url, asPath, { shallow: true })
59+
// Router.push(url, asPath, { shallow: true })
6060
// see: https://stackoverflow.com/questions/824349/modify-the-url-without-reloading-the-page
6161
/* return Global.history.pushState({}, null, url) */
62+
// NOTE: Router.push(url, asPath, { shallow: true }) is not working on pruction env
63+
return Global.history.pushState({}, null, asPath)
6264
},
6365
markState(sobj) {
6466
markStates(sobj, self)

0 commit comments

Comments
 (0)