react-router MemoryRouter.initialEntries

* Use History.LocationDescriptor[]
* Add example
This commit is contained in:
Michael Strobel
2017-03-27 11:26:32 +08:00
parent 49f185c6ec
commit 4a2542e4af
3 changed files with 45 additions and 1 deletions

View File

@@ -30,7 +30,7 @@ declare module 'react-router' {
}
}
interface MemoryRouterProps {
initialEntries?: H.Location[];
initialEntries?: H.LocationDescriptor[];
initialIndex?: number;
getUserConfirmation?: () => void;
keyLength?: number;

View 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

View File

@@ -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",