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

How do you change routes... #16

Closed
bingomanatee opened this issue Nov 25, 2015 · 4 comments
Closed

How do you change routes... #16

bingomanatee opened this issue Nov 25, 2015 · 4 comments

Comments

@bingomanatee
Copy link

without reloading the page? there are tricks like transitionTo and history in react-router; do these work with react-routing as well?

Dave

@subodh-malgonde
Copy link

If you are using the react-starter-kit, then there is a Location module. Use

Location.pushState(null, '/to/path')

@subodh-malgonde
Copy link

@koistya is this the right way?

@koistya
Copy link
Member

koistya commented Dec 12, 2015

Check the new history API documentation. As an example, in React Starter Kit there is Location class which is just a singleton instance of history module. You can use it to transition between screens/pages on the client like so.

import React from 'react';
import Location from '../core/Location';

function navigateToPath(event) {
  event.preventDefault();
  Location.push('/to/path');
}

function navigateToPathWithState(event) {
  event.preventDefault();
  Location.push({ pathname: '/to/path', state: { foo: 123 } });
}

// Stateless functional React component
function MyComponent() {
  return (
    <div>
      <button onClick={navigateToPath}>Click me (1)</button>
      <button onClick={navigateToPathWithState}>Click me (2)</button>
    </div>
  );
}

export default MyComponent;

And inside the client-side bootstrap code (src/app.js), there is a listener which catches such redirects and makes sure that transition occurs without full-page refresh (see Location.listen(...) in src/app.js).

Summary

react-routing is responsible only for routing (both client-side and server-side) and history module is responsible for navigation (client-side).

@koistya koistya closed this as completed Dec 12, 2015
@alexgvozden
Copy link

alexgvozden commented Dec 13, 2017

what happened to Location and what is the replacement?

EDIT: now it's easy to use history from history.js in kit or just reference createBrowserHistory();

history.push("/login")

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