1 | /**
|
2 | * 检查下一个路由状态和当前客户端的 location 是否一致。多用于针对基于路由代码拆分的当前路由检测。
|
3 | * @param {Object} nextState `react-router` 传入的下一个路由状态对象
|
4 | * @param {Boolean} [isAlwaysTrue=false] 是否默认为 `true`
|
5 | * @returns {Boolean}
|
6 | */
|
7 | module.exports = (nextState, isAlwaysTrue) => {
|
8 | if (isAlwaysTrue ||
|
9 | typeof location === 'undefined' ||
|
10 | __SERVER__ ||
|
11 | __SPA__
|
12 | ) return true
|
13 |
|
14 | let next = nextState.location.pathname
|
15 | let curr = location.pathname
|
16 |
|
17 | if (next.substr(0, 1) !== '/') next = '/' + next
|
18 | if (curr.substr(0, 1) !== '/') curr = '/' + curr
|
19 |
|
20 | return Boolean(next === curr)
|
21 | }
|