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
3085ccc1
Commit
3085ccc1
authored
Mar 17, 2019
by
Wee
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: implement `onHide` and `onReappear`
parent
3e00ae94
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
8 deletions
+29
-8
LiveRoute.tsx
src/LiveRoute.tsx
+29
-8
No files found.
src/LiveRoute.tsx
View file @
3085ccc1
import
{
History
}
from
'history'
import
{
History
,
Location
}
from
'history'
import
*
as
React
from
'react'
import
*
as
React
from
'react'
import
*
as
ReactDOM
from
'react-dom'
import
*
as
ReactDOM
from
'react-dom'
import
{
isValidElementType
}
from
'react-is'
import
{
isValidElementType
}
from
'react-is'
...
@@ -165,6 +165,9 @@ class LiveRoute extends React.Component<IProps, any> {
...
@@ -165,6 +165,9 @@ class LiveRoute extends React.Component<IProps, any> {
sensitive
=
false
,
sensitive
=
false
,
strict
=
false
,
strict
=
false
,
history
,
history
,
onReappear
,
onHide
,
forceUnmount
,
location
,
location
,
match
:
matchFromProps
,
match
:
matchFromProps
,
path
,
path
,
...
@@ -177,23 +180,41 @@ class LiveRoute extends React.Component<IProps, any> {
...
@@ -177,23 +180,41 @@ class LiveRoute extends React.Component<IProps, any> {
let
{
children
}
=
this
.
props
let
{
children
}
=
this
.
props
const
matchOfPath
=
matchPath
((
location
as
any
).
pathname
,
this
.
props
)
const
matchOfPath
=
matchPath
((
location
as
any
).
pathname
,
this
.
props
)
const
matchOfLivePath
=
const
matchOfLivePath
=
this
.
isLivePathMatch
(
livePath
,
location
!
.
pathname
,
{
this
.
isLivePathMatch
(
livePath
,
location
!
.
pathname
,
{
path
,
path
,
exact
,
exact
,
strict
,
strict
,
sensitive
sensitive
})
})
||
alwaysLive
const
matchAnyway
=
matchOfPath
||
matchOfLivePath
const
matchAnyway
=
matchOfPath
||
matchOfLivePath
// normal render
if
(
matchOfPath
)
{
if
(
matchOfPath
)
{
this
.
showRoute
()
this
.
showRoute
()
this
.
restoreScrollPosition
()
this
.
restoreScrollPosition
()
this
.
clearScroll
()
this
.
clearScroll
()
// hide -> show
if
(
this
.
liveState
===
LiveState
.
HIDE_RENDER
)
{
if
(
typeof
onReappear
===
'function'
)
{
onReappear
(
location
!
,
matchAnyway
,
livePath
,
alwaysLive
)
}
}
this
.
liveState
=
LiveState
.
NORMAL_RENDER_MATCHED
}
}
// hide render
if
(
!
matchOfPath
&&
matchAnyway
)
{
if
(
!
matchOfPath
&&
matchAnyway
)
{
this
.
saveScrollPosition
()
this
.
saveScrollPosition
()
this
.
hideRoute
()
this
.
hideRoute
()
// show -> hide
if
(
this
.
liveState
===
LiveState
.
NORMAL_RENDER_MATCHED
)
{
if
(
typeof
onHide
===
'function'
)
{
onHide
(
location
!
,
matchAnyway
,
livePath
,
alwaysLive
)
}
}
this
.
liveState
=
LiveState
.
HIDE_RENDER
}
}
const
props
=
{
...
staticContext
,
location
,
match
:
matchAnyway
}
const
props
=
{
...
staticContext
,
location
,
match
:
matchAnyway
}
...
...
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