Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

React Router v4.0 Breaking changes #25

Open
KhalilMohammad opened this issue Aug 6, 2017 · 4 comments
Open

React Router v4.0 Breaking changes #25

KhalilMohammad opened this issue Aug 6, 2017 · 4 comments

Comments

@KhalilMohammad
Copy link

Router v4 is a little bit different

HashHistory

import  { HashRouter as Router, Route } from 'react-router-dom';
import App from './components/App'; 
render((
    <Router>
        <Route exact path="/" component={App} />
     </Router>  ),
document.getElementById('root'));

BrowserHistory

import { BrowserRouter as Router, Route } from 'react-router-dom';
import App from './components/App';
render((
     <Router>
         <Route exact path="/" component={App} />    
      </Router> ),  
 document.getElementById('root'));
@arrmixer
Copy link

arrmixer commented Aug 8, 2017

Hey thanks!
I'll try them. I was going to attempt to update to Router v4 once I was done with the project as a refactoring job.

@KhalilMohammad
Copy link
Author

Welcome,
Since there are multiple breaking changes in React Router v4.
You can ask me for any problem.
I will try to help when possible.

@DrewDrinkwater
Copy link

DrewDrinkwater commented Aug 22, 2017

This is what I ended up with for the "Simple Routing" section using the latest React Router:

import 'babel-polyfill';
import React from 'react';
import ReactDOM from 'react-dom';
import  { HashRouter as Router, Route, Switch } from 'react-router-dom';

import IssueList from './IssueList.jsx';
import IssueEdit from './IssueEdit.jsx';

const contentNode = document.getElementById('contents');
const NoMatch = () => <p>Page Not Found</p>;

const RoutedApp = () => (
    <Router>
        <Switch>
            <Route exact path="/" component={IssueList} />
            <Route path="/issueEdit" component={IssueEdit} />
            <Route path="*" component={NoMatch} />
        </Switch>
    </Router>
);

ReactDOM.render(<RoutedApp />, contentNode);

if (module.hot) {
    module.hot.accept();
}

@orangesoncom
Copy link

orangesoncom commented Jan 23, 2018

Hi @DrewDrinkwater, @KhalilMohammad
Can you show me the code of IssueEdit.jsx based on Route Parameter in Chapter 8.
I clicked the link on the id field but have no luck, the page doesn't change even the url has been changed like this (http://localhost:8000/#/issues/5a6339c8ea5f506eb300582f)
here is my App.jsx

import 'babel-polyfill';
import React from 'react';
import ReactDOM from 'react-dom';
import { HashRouter as Router, Route, Switch, Redirect } from 'react-router-dom';

import IssueList from './IssueList.jsx';
import IssueEdit from './IssueEdit.jsx';

const contentNode = document.getElementById('contents');
const NoMatch = () => <p>Page not Found</p>;

const RoutedApp = () => (
  <Router>
    <Switch>
      <Redirect exact from="/" to="/issues" />
      <Route path="/issues" component={IssueList} />
      <Route path="/issues/:id" component={IssueEdit} />
      <Route path="*" component={NoMatch} />
    </Switch>
  </Router>
);

ReactDOM.render(<RoutedApp />, contentNode); // Render the component inside the content Node

if (module.hot) {
  module.hot.accept();
}

and the IssueEdit.jsx

import React from 'react';
import { Link } from 'react-router-dom';
import PropTypes from 'prop-types';

export default class IssueEdit extends React.Component {
  render() {
    return (
      <div>
        This is placeholder for edit {this.props.match.params.id}
        <Link to="/issues">Back to Issue List.</Link>
      </div>
    );
  }
}

IssueEdit.propTypes = { 
  match: PropTypes.shape({
    params: PropTypes.shape({
      id: PropTypes.string.isRequired
    })
  }),
};

Edit:
It's works now after change route section like this
<Route exact path="/issues" component={IssueList} />

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants