Skip to content
This repository was archived by the owner on Apr 8, 2020. It is now read-only.

Commit d2c56d1

Browse files
Keven van ZuijlenSteveSandersonMS
authored andcommitted
Implemented react-router-dom v4
1 parent 7a11cf9 commit d2c56d1

File tree

4 files changed

+17
-17
lines changed

4 files changed

+17
-17
lines changed

templates/ReactSpa/ClientApp/boot.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ import './css/site.css';
22
import 'bootstrap';
33
import * as React from 'react';
44
import * as ReactDOM from 'react-dom';
5-
import { browserHistory, Router } from 'react-router';
5+
import { BrowserRouter as Router } from 'react-router-dom';
66
import routes from './routes';
77

88
// This code starts up the React app when it runs in a browser. It sets up the routing configuration
99
// and injects the app into a DOM element.
1010
ReactDOM.render(
11-
<Router history={ browserHistory } children={ routes } />,
11+
<Router children={ routes } />,
1212
document.getElementById('react-app')
1313
);

templates/ReactSpa/ClientApp/components/Layout.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as React from 'react';
22
import { NavMenu } from './NavMenu';
33

44
export interface LayoutProps {
5-
body: React.ReactElement<any>;
5+
children?: React.ReactNode;
66
}
77

88
export class Layout extends React.Component<LayoutProps, {}> {
@@ -13,7 +13,7 @@ export class Layout extends React.Component<LayoutProps, {}> {
1313
<NavMenu />
1414
</div>
1515
<div className='col-sm-9'>
16-
{ this.props.body }
16+
{ this.props.children }
1717
</div>
1818
</div>
1919
</div>;

templates/ReactSpa/ClientApp/components/NavMenu.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as React from 'react';
2-
import { Link } from 'react-router';
2+
import { Link, NavLink } from 'react-router-dom';
33

44
export class NavMenu extends React.Component<{}, {}> {
55
public render() {
@@ -18,19 +18,19 @@ export class NavMenu extends React.Component<{}, {}> {
1818
<div className='navbar-collapse collapse'>
1919
<ul className='nav navbar-nav'>
2020
<li>
21-
<Link to={ '/' } activeClassName='active'>
21+
<NavLink to={ '/' } exact activeClassName='active'>
2222
<span className='glyphicon glyphicon-home'></span> Home
23-
</Link>
23+
</NavLink>
2424
</li>
2525
<li>
26-
<Link to={ '/counter' } activeClassName='active'>
26+
<NavLink to={ '/counter' } activeClassName='active'>
2727
<span className='glyphicon glyphicon-education'></span> Counter
28-
</Link>
28+
</NavLink>
2929
</li>
3030
<li>
31-
<Link to={ '/fetchdata' } activeClassName='active'>
31+
<NavLink to={ '/fetchdata' } activeClassName='active'>
3232
<span className='glyphicon glyphicon-th-list'></span> Fetch data
33-
</Link>
33+
</NavLink>
3434
</li>
3535
</ul>
3636
</div>

templates/ReactSpa/ClientApp/routes.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import * as React from 'react';
2-
import { Router, Route, HistoryBase } from 'react-router';
2+
import { Route } from 'react-router-dom';
33
import { Layout } from './components/Layout';
44
import { Home } from './components/Home';
55
import { FetchData } from './components/FetchData';
66
import { Counter } from './components/Counter';
77

8-
export default <Route component={ Layout }>
9-
<Route path='/' components={{ body: Home }} />
10-
<Route path='/counter' components={{ body: Counter }} />
11-
<Route path='/fetchdata' components={{ body: FetchData }} />
12-
</Route>;
8+
export default <Layout>
9+
<Route exact path='/' component={ Home } />
10+
<Route path='/counter' component={ Counter } />
11+
<Route path='/fetchdata' component={ FetchData } />
12+
</Layout>;
1313

1414
// Allow Hot Module Reloading
1515
declare var module: any;

0 commit comments

Comments
 (0)