Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
R
react-live-route
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
fukai
react-live-route
Commits
6e1d3d0b
Commit
6e1d3d0b
authored
Jul 07, 2018
by
Wee
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(test): use original version test of rr4
parent
a614346b
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
11 additions
and
22 deletions
+11
-22
Switch.js
modules/react-router/Switch.js
+7
-7
StaticRouter-test.js
modules/react-router/__tests__/StaticRouter-test.js
+1
-0
generatePath.js
modules/react-router/generatePath.js
+1
-1
matchPath.js
modules/react-router/matchPath.js
+1
-13
withRouter.js
modules/react-router/withRouter.js
+1
-1
No files found.
modules/react-router/Switch.js
View file @
6e1d3d0b
...
@@ -41,17 +41,17 @@ class Switch extends React.Component {
...
@@ -41,17 +41,17 @@ class Switch extends React.Component {
render
()
{
render
()
{
const
{
route
}
=
this
.
context
.
router
;
const
{
route
}
=
this
.
context
.
router
;
const
{
children
}
=
this
.
props
;
const
{
children
}
=
this
.
props
;
const
location
=
this
.
props
.
location
||
route
.
location
;
// 可以手动指定 location
const
location
=
this
.
props
.
location
||
route
.
location
;
let
match
,
child
;
let
match
,
child
;
React
.
Children
.
forEach
(
children
,
element
=>
{
React
.
Children
.
forEach
(
children
,
element
=>
{
if
(
match
==
null
&&
React
.
isValidElement
(
element
))
{
if
(
match
==
null
&&
React
.
isValidElement
(
element
))
{
const
{
const
{
path
:
pathProp
,
// path
path
:
pathProp
,
exact
,
// 路径完全匹配
exact
,
strict
,
// 是否结尾匹配带/的路径
strict
,
sensitive
,
// 大小写敏感
sensitive
,
from
// path 的备胎
from
}
=
element
.
props
;
}
=
element
.
props
;
const
path
=
pathProp
||
from
;
const
path
=
pathProp
||
from
;
...
@@ -65,7 +65,7 @@ class Switch extends React.Component {
...
@@ -65,7 +65,7 @@ class Switch extends React.Component {
});
});
return
match
return
match
?
React
.
cloneElement
(
child
,
{
location
,
computedMatch
:
match
})
// 重新计算两个参数
?
React
.
cloneElement
(
child
,
{
location
,
computedMatch
:
match
})
:
null
;
:
null
;
}
}
}
}
...
...
modules/react-router/__tests__/StaticRouter-test.js
View file @
6e1d3d0b
...
@@ -5,6 +5,7 @@ import PropTypes from "prop-types";
...
@@ -5,6 +5,7 @@ import PropTypes from "prop-types";
import
StaticRouter
from
"../StaticRouter"
;
import
StaticRouter
from
"../StaticRouter"
;
import
Redirect
from
"../Redirect"
;
import
Redirect
from
"../Redirect"
;
import
Route
from
"../../LiveRoute"
;
import
Route
from
"../../LiveRoute"
;
// import Route from "../Route";
import
Prompt
from
"../Prompt"
;
import
Prompt
from
"../Prompt"
;
describe
(
"A <StaticRouter>"
,
()
=>
{
describe
(
"A <StaticRouter>"
,
()
=>
{
...
...
modules/react-router/generatePath.js
View file @
6e1d3d0b
...
@@ -28,7 +28,7 @@ const generatePath = (pattern = "/", params = {}) => {
...
@@ -28,7 +28,7 @@ const generatePath = (pattern = "/", params = {}) => {
return
pattern
;
return
pattern
;
}
}
const
generator
=
compileGenerator
(
pattern
);
const
generator
=
compileGenerator
(
pattern
);
return
generator
(
params
);
return
generator
(
params
,
{
pretty
:
true
}
);
};
};
export
default
generatePath
;
export
default
generatePath
;
modules/react-router/matchPath.js
View file @
6e1d3d0b
import
pathToRegexp
from
"path-to-regexp"
;
import
pathToRegexp
from
"path-to-regexp"
;
// ES6 的 import 会共享,所以可以理解为一个全局缓存
// 缓存的结构是 option 对象下的 pattern
const
patternCache
=
{};
const
patternCache
=
{};
const
cacheLimit
=
10000
;
const
cacheLimit
=
10000
;
let
cacheCount
=
0
;
let
cacheCount
=
0
;
...
@@ -16,12 +14,6 @@ const compilePath = (pattern, options) => {
...
@@ -16,12 +14,6 @@ const compilePath = (pattern, options) => {
const
re
=
pathToRegexp
(
pattern
,
keys
,
options
);
const
re
=
pathToRegexp
(
pattern
,
keys
,
options
);
const
compiledPattern
=
{
re
,
keys
};
const
compiledPattern
=
{
re
,
keys
};
// 这是 path-to-regex 的返回值
// var keys = []
// var re = pathToRegexp('/foo/:bar', keys)
// re = /^\/foo\/([^\/]+?)\/?$/i
// keys = [{ name: 'bar', prefix: '/', delimiter: '/', optional: false, repeat: false, pattern: '[^\\/]+?' }]
if
(
cacheCount
<
cacheLimit
)
{
if
(
cacheCount
<
cacheLimit
)
{
cache
[
pattern
]
=
compiledPattern
;
cache
[
pattern
]
=
compiledPattern
;
cacheCount
++
;
cacheCount
++
;
...
@@ -40,18 +32,14 @@ const matchPath = (pathname, options = {}, parent) => {
...
@@ -40,18 +32,14 @@ const matchPath = (pathname, options = {}, parent) => {
if
(
path
==
null
)
return
parent
;
if
(
path
==
null
)
return
parent
;
// path-to-regex 的 end 相当于就是 router 的 exact,相当于是否使用全局匹配 /g
const
{
re
,
keys
}
=
compilePath
(
path
,
{
end
:
exact
,
strict
,
sensitive
});
const
{
re
,
keys
}
=
compilePath
(
path
,
{
end
:
exact
,
strict
,
sensitive
});
// 使用生成的正则表达式去匹配
const
match
=
re
.
exec
(
pathname
);
const
match
=
re
.
exec
(
pathname
);
// 不匹配直接返回
if
(
!
match
)
return
null
;
if
(
!
match
)
return
null
;
const
[
url
,
...
values
]
=
match
;
const
[
url
,
...
values
]
=
match
;
const
isExact
=
pathname
===
url
;
const
isExact
=
pathname
===
url
;
// 如果在要求 exact 匹配时为非 exact 的匹配,则直接返回
if
(
exact
&&
!
isExact
)
return
null
;
if
(
exact
&&
!
isExact
)
return
null
;
return
{
return
{
...
...
modules/react-router/withRouter.js
View file @
6e1d3d0b
...
@@ -24,7 +24,7 @@ const withRouter = Component => {
...
@@ -24,7 +24,7 @@ const withRouter = Component => {
C
.
displayName
=
`withRouter(
${
Component
.
displayName
||
Component
.
name
}
)`
;
C
.
displayName
=
`withRouter(
${
Component
.
displayName
||
Component
.
name
}
)`
;
C
.
WrappedComponent
=
Component
;
C
.
WrappedComponent
=
Component
;
C
.
propTypes
=
{
C
.
propTypes
=
{
wrappedComponentRef
:
PropTypes
.
func
wrappedComponentRef
:
PropTypes
.
func
};
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment