Commit 9225579f by zhanghaozhe

route-bug

parent 90fabc1e
import React, { Component } from 'react'
import Routes from './router'
import cookie from 'js-cookie'
import { connect } from "react-redux";
import { setCurrentUser, startFetchUser } from "@/store/userAction";
import { connect } from "react-redux"
import { setCurrentUser, startFetchUser } from "@/store/userAction"
import { withRouter } from 'react-router-dom'
import { compose } from 'redux'
import { getParam, http, browser } from "@/utils";
import { Toast } from "antd-mobile";
import { getParam, http, browser } from "@/utils"
import { Toast } from "antd-mobile"
import { addDays } from 'date-fns'
......@@ -16,39 +16,24 @@ mock()*/
// 默认样式
import './assets/css/index.scss';
import './assets/css/index.scss'
// iconfont
import './assets/font/iconfont.css';
import './assets/font/iconfont.css'
class App extends Component {
previousLocation = {
...{
state: {
from:
{
pathname: this.props.location.pathname,
search: this.props.location.search,
hash: this.props.location.hash
}
}
},
...this.props.location
}
previousLocation = {pathname: '/', search: '', hash: ''}
records = []
pathnameBlacklist = ['/country', '/passport']
firstLoad = true
componentDidMount() {
// 友盟统计
const script = document.createElement('script');
script.src = 'https://s22.cnzz.com/z_stat.php?id=1265696973&web_id=1265696973';
script.language = 'JavaScript';
document.body.appendChild(script);
this.setNavigationRecord(this.props.location, this.props.history.action)
this.umengStatistic()
//平台信息
......@@ -60,21 +45,34 @@ class App extends Component {
this.getUser()
this.utm()
const routeMatchRule = /binding-tel|forgot|set-password/
const {history} = this.props
this.setNavigationRecord(this.props.location, this.props.history.action)
this.setPreviousLocation()
history.listen((location, action) => {
this.firstLoad = false
this.setNavigationRecord(location, action)
this.utm()
if (cookie.get('uid') && this.props.user.hasError) {
this.getUser()
}
const {pathname} = location
const {pathname, state} = location
if (pathname.startsWith('/passport')) {
if (routeMatchRule.test(pathname)) {
return
location.state = {
...state,
...{
from: {
pathname: this.previousLocation.pathname,
search: this.previousLocation.search,
hash: this.previousLocation.hash
}
}
}
location.state = {...location.state, ...{from: this.previousLocation}};
} else {
this.removeShareCodeCookie()
}
......@@ -83,6 +81,14 @@ class App extends Component {
}
umengStatistic = () => {
// 友盟统计
const script = document.createElement('script')
script.src = 'https://s22.cnzz.com/z_stat.php?id=1265696973&web_id=1265696973'
script.language = 'JavaScript'
document.body.appendChild(script)
}
removeShareCodeCookie = () => {
cookie.remove('share_code', {path: '/', domain: '.julyedu.com'})
}
......@@ -103,7 +109,7 @@ class App extends Component {
location.state && location.state.records
? (location.state.records = this.records)
: location.state? location.state = {...location.state, records: this.records}
: location.state ? location.state = {...location.state, records: this.records}
: (location.state = {records: this.records})
}
......@@ -134,7 +140,7 @@ class App extends Component {
}
getUser = () => {
//获取用户信息
this.props.startFetchUser()
http.get(`${API.home}/m/user_info`).then(res => {
this.props.setCurrentUser(this.transformUser(res))
......@@ -179,23 +185,9 @@ class App extends Component {
}
setPreviousLocation = () => {
const {location, history: {action}} = this.props
if (location.pathname.startsWith('/passport')) {
let index = this.records.findIndex(item => item.pathname.startsWith('/passport'))
this.previousLocation = index > 0
? this.records[index - 1]
: this.records.length
? this.records[this.records.length - 1]
: null
} else {
if (action === 'POP' || action === 'REPLACE') {
let index = this.records.findIndex(item => item.pathname.startsWith('/passport'))
this.previousLocation = index > 0 ? this.records[index - 1] : this.records[this.records.length - 1]
} else {
this.previousLocation = location
}
}
const {location} = this.props
let isInBlacklist = this.pathnameBlacklist.some(item => location.pathname.startsWith(item))
!isInBlacklist && (this.previousLocation = location)
}
transformUser = res => {
......
......@@ -40,7 +40,7 @@ class MyEdut extends PureComponent {
// 退出登录
outLogin = () => {
this.props.logout()
Toast.info('已退出', 2)
Toast.info('已退出', 2, null, false)
this.props.history.push('/my')
}
......
......@@ -9,9 +9,9 @@ import ForgotPassword from './forgotPassword'
import SetPassword from './setPassword'
import BindingTel from './bindingTel'
import ForgotPasswordEmail from './forgotPasswordEmail'
import { connect } from "react-redux";
import { compose } from "redux";
import {getParam} from "@/utils";
import { connect } from "react-redux"
import { compose } from "redux"
import { getParam } from "@/utils"
import account from './icons/account.png'
import qq from './icons/qq.png'
......@@ -22,12 +22,13 @@ import wechat from './icons/wechat.png'
class Passport extends Component {
redirectURL = '/'
count = 1
constructor(props) {
super(props);
super(props)
const {location} = props
const {pathname, search, hash} = location
const {from} = location.state || {from: {pathname: pathname, search: search, hash: hash}}
const from = location.state && location.state.from || {pathname: pathname, search: search, hash: hash}
this.redirectURL = window.location.origin + from.pathname + from.search + from.hash
this.state = {
loginWays: [
......@@ -60,27 +61,33 @@ class Passport extends Component {
componentDidMount() {
this.routeWhenUserLoggedIn()
const {history} = this.props
if (!window.passportHistoryListener) {
this.unlisten = history.listen((location, action) => {
window.passportHistoryListener = this.unlisten
location.pathname !== '/country' && !location.pathname.startsWith('/passport') && this.unlisten()
if (action === 'PUSH') {
this.count++
} else if (action === 'POP') {
this.count--
}
})
}
}
componentDidUpdate() {
this.routeWhenUserLoggedIn()
}
routeWhenUserLoggedIn = () => {
let {history, location} = this.props
let {data} = this.props.user
if (data && Object.values(data).filter(item => !!item).length) {
if (history.action === 'POP' && history.length <= 3) {
history.push('/')
} else {
if (!(this.props.user && this.props.user.stage)) {
const from = location.state && location.state.from || {pathname: '/', search: ''};
const redirectURI = getParam('redirect')
redirectURI ? (window.location.href = redirectURI) : history.replace(from);
}
}
let {hasError} = this.props.user
if (!hasError) {
const redirectURI = getParam('redirect')
redirectURI ? (window.location.href = redirectURI) : this.props.history.go(-this.count)
}
}
......
......@@ -29,8 +29,8 @@ const MyEdit = loadable(() => import(/* webpackChunkName: 'MyEdit'*/'@/component
const Classify = loadable(() => import(/* webpackChunkName: 'Classify'*/'@/components/classify'))
const CampTest = loadable(() => import(/* webpackChunkName: 'Classify'*/'@/components/video/camp/campTest'))
const CampResolve = loadable(() => import(/* webpackChunkName: 'Classify'*/'@/components/video/camp/campResolve'))
const ShareCourse = loadable(() => import('@/components/ShareCourse/index'))
const Country = loadable(() => import('@/components/country/index'))
const ShareCourse = loadable(() => import(/* webpackChunkName: 'ShareCourse'*/'@/components/ShareCourse/index'))
const Country = loadable(() => import(/* webpackChunkName: 'Country' */'@/components/country/index'))
export default [
{
path: '/',
......
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