mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-23 21:00:01 +08:00
react-router MemoryRouter.initialEntries
* Use History.LocationDescriptor[] * Add example
This commit is contained in:
2
types/react-router/index.d.ts
vendored
2
types/react-router/index.d.ts
vendored
@@ -30,7 +30,7 @@ declare module 'react-router' {
|
||||
}
|
||||
}
|
||||
interface MemoryRouterProps {
|
||||
initialEntries?: H.Location[];
|
||||
initialEntries?: H.LocationDescriptor[];
|
||||
initialIndex?: number;
|
||||
getUserConfirmation?: () => void;
|
||||
keyLength?: number;
|
||||
|
||||
43
types/react-router/test/MemoryRouter.tsx
Normal file
43
types/react-router/test/MemoryRouter.tsx
Normal file
@@ -0,0 +1,43 @@
|
||||
import * as React from 'react'
|
||||
import {
|
||||
MemoryRouter,
|
||||
Route,
|
||||
Link
|
||||
} from 'react-router-dom'
|
||||
|
||||
const initialRouterEntries = [
|
||||
'/',
|
||||
{
|
||||
pathname: '/about'
|
||||
}
|
||||
]
|
||||
|
||||
const MemoryRouterExample = () => (
|
||||
<MemoryRouter initialEntries={[initialRouterEntries]} initialIndex={1}>
|
||||
<div>
|
||||
<ul>
|
||||
<li><Link to="/">Home</Link></li>
|
||||
<li><Link to="/about">About</Link></li>
|
||||
</ul>
|
||||
|
||||
<hr/>
|
||||
|
||||
<Route exact path="/" component={Home}/>
|
||||
<Route path="/about" component={About}/>
|
||||
</div>
|
||||
</MemoryRouter>
|
||||
)
|
||||
|
||||
const Home = () => (
|
||||
<div>
|
||||
<h2>Home</h2>
|
||||
</div>
|
||||
)
|
||||
|
||||
const About = () => (
|
||||
<div>
|
||||
<h2>About</h2>
|
||||
</div>
|
||||
)
|
||||
|
||||
export default MemoryRouterExample
|
||||
@@ -21,6 +21,7 @@
|
||||
"test/CustomLink.tsx",
|
||||
"test/ModalGallery.tsx",
|
||||
"test/NavigateWithContext.tsx",
|
||||
"test/MemoryRouter.tsx",
|
||||
"test/NoMatch.tsx",
|
||||
"test/Params.tsx",
|
||||
"test/PreventingTransitions.tsx",
|
||||
|
||||
Reference in New Issue
Block a user