Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
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
Alex
next.js
Commits
b509841f
Commit
b509841f
authored
Apr 03, 2019
by
JJ Kasper
Committed by
Tim Neutkens
Apr 03, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add useRouter hook (#6869)
This introduces the `useRouter` hook alternative to `withRouter`
parent
4b44778b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
0 deletions
+6
-0
router.js
packages/next/client/router.js
+6
-0
No files found.
packages/next/client/router.js
View file @
b509841f
/* global window */
/* global window */
import
React
from
'react'
import
_Router
from
'next-server/dist/lib/router/router'
import
_Router
from
'next-server/dist/lib/router/router'
import
{
RouterContext
}
from
'next-server/dist/lib/router-context'
const
SingletonRouter
=
{
const
SingletonRouter
=
{
router
:
null
,
// holds the actual router instance
router
:
null
,
// holds the actual router instance
...
@@ -75,6 +77,10 @@ export default SingletonRouter
...
@@ -75,6 +77,10 @@ export default SingletonRouter
// Reexport the withRoute HOC
// Reexport the withRoute HOC
export
{
default
as
withRouter
}
from
'./with-router'
export
{
default
as
withRouter
}
from
'./with-router'
export
function
useRouter
()
{
return
React
.
useContext
(
RouterContext
)
}
// INTERNAL APIS
// INTERNAL APIS
// -------------
// -------------
// (do not use following exports inside the app)
// (do not use following exports inside the app)
...
...
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