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

Replace react-router with @reach/router #6918

Merged
merged 27 commits into from
Aug 6, 2018
Merged

Replace react-router with @reach/router #6918

merged 27 commits into from
Aug 6, 2018

Conversation

KyleAMathews
Copy link
Contributor

@KyleAMathews KyleAMathews commented Aug 1, 2018

fixes #5656

Smaller package + better accessibility + simplified APIs 👍

https://reach.tech/router/

TODO

  • remove console.log
  • fix conflicts
  • fix gatsby-link typescript typings
  • create issue for hash scrolling handling
  • for removed APIs, investigate why they were added
  • Update gatsby-link tests

Upgrade sites

  • store.gatsbyjs.org
  • client-only-routes
  • simple-auth

Document

  • gatsby-link

Breaking changes to document

  • change client paths to use splats
  • note that can't use relative paths Add support for relative links with @reach/router #6945
  • don't support object form of to any longer. Add search/hash yourself. Add state to state prop.
  • change Route components to Router w/ normal components with path prop
  • on gatsby-link, now only support activeClass / activeStyle props. If want more control, you can use getProps prop
  • route apis don't get action anymore
  • Migrating removed browser APIs

@KyleAMathews
Copy link
Contributor Author

KyleAMathews commented Aug 1, 2018

Deploy preview for using-postcss-sass failed.

Built with commit 06d9c77

https://app.netlify.com/sites/using-postcss-sass/deploys/5b682dae73f2cf4f594f7750

@KyleAMathews
Copy link
Contributor Author

KyleAMathews commented Aug 1, 2018

Deploy preview for using-glamor failed.

Built with commit 06d9c77

https://app.netlify.com/sites/using-glamor/deploys/5b682daf73f2cf4f594f7759

@KyleAMathews
Copy link
Contributor Author

KyleAMathews commented Aug 1, 2018

Deploy preview for using-contentful failed.

Built with commit 06d9c77

https://app.netlify.com/sites/using-contentful/deploys/5b682db073f2cf4f594f775f

@KyleAMathews
Copy link
Contributor Author

KyleAMathews commented Aug 1, 2018

Deploy preview for using-jss failed.

Built with commit 06d9c77

https://app.netlify.com/sites/using-jss/deploys/5b682db373f2cf4f594f7777

@gatsbybot
Copy link
Collaborator

gatsbybot commented Aug 1, 2018

Deploy preview for using-drupal failed.

Built with commit 06d9c77

https://app.netlify.com/sites/using-drupal/deploys/5b682dae73f2cf4f594f774a

@KyleAMathews
Copy link
Contributor Author

KyleAMathews commented Aug 1, 2018

Deploy preview for gatsbygram failed.

Built with commit 06d9c77

https://app.netlify.com/sites/gatsbygram/deploys/5b682dae73f2cf4f594f7747

@KyleAMathews
Copy link
Contributor Author

KyleAMathews commented Aug 1, 2018

Deploy preview for using-remark failed.

Built with commit 06d9c77

https://app.netlify.com/sites/using-remark/deploys/5b682db073f2cf4f594f7762

@KyleAMathews
Copy link
Contributor Author

KyleAMathews commented Aug 1, 2018

Deploy preview for gatsbyjs failed.

Built with commit 06d9c77

https://app.netlify.com/sites/gatsbyjs/deploys/5b682dae73f2cf4f594f7744

@KyleAMathews KyleAMathews added this to Needs Verification in Gatsby v2 Release via automation Aug 1, 2018
@KyleAMathews KyleAMathews moved this from Needs Verification to In progress in Gatsby v2 Release Aug 1, 2018
@KyleAMathews
Copy link
Contributor Author

I'm doing an overview call on this in 10 minutes if you'd like to join! https://zoom.us/j/100692813

}
}

// Make sure the necessary scripts and data are
// loaded before continuing.
e.preventDefault()
window.___push(this.state.to)
if (process.env.NODE_ENV === `production`) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove production check


setApiRunnerForLoader(apiRunner)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove

@KyleAMathews
Copy link
Contributor Author

KyleAMathews commented Aug 3, 2018

Deploy preview for using-styled-components failed.

Built with commit bc7035c

https://app.netlify.com/sites/using-styled-components/deploys/5b682bab792f8943ae9ddcec

@pieh pieh mentioned this pull request Aug 3, 2018
getProps = ({ isCurrent }) =>
isCurrent
? {
className: this.props.activeClassName,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to add default className (similiar how styles are merged in line below)
react-router's NavLink does that - https://github.com/ReactTraining/react-router/blob/master/packages/react-router-dom/modules/NavLink.js#L41-L42 if we want to maintain backward compatibility

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah good catch, fixed in 33583a2

@KyleAMathews
Copy link
Contributor Author

Deploy preview for image-processing failed.

Built with commit 7c61690

https://app.netlify.com/sites/image-processing/deploys/5b681c3482d3f128bebdcdb4

@KyleAMathews
Copy link
Contributor Author

KyleAMathews commented Aug 6, 2018

Deploy preview for image-processing failed.

Built with commit bc7035c

https://app.netlify.com/sites/image-processing/deploys/5b682baa792f8943ae9ddce6

@KyleAMathews KyleAMathews changed the title [wip] Replace react-router with @reach/router fixes #5656 Replace react-router with @reach/router fixes #5656 Aug 6, 2018
@KyleAMathews KyleAMathews changed the title Replace react-router with @reach/router fixes #5656 Replace react-router with @reach/router Aug 6, 2018
Copy link
Contributor

@pieh pieh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@KyleAMathews KyleAMathews merged commit 5778c27 into master Aug 6, 2018
Gatsby v2 Release automation moved this from In progress to Done Aug 6, 2018
@KyleAMathews KyleAMathews deleted the reach-router branch August 6, 2018 11:24
@justinwaite
Copy link
Contributor

Any idea on when docs would be updated for the client only routes using @reach/router?

@KyleAMathews
Copy link
Contributor Author

@jdeanwaite they are e.g. https://next.gatsbyjs.org/docs/building-apps-with-gatsby/ and https://next.gatsbyjs.org/docs/migrating-from-v1-to-v2/#migrate-from-react-router-to-reachrouter

@justinwaite
Copy link
Contributor

@KyleAMathews Thanks for that, and thanks for all of the work you are doing on Gatsby!

@deadcoder0904
Copy link
Contributor

deadcoder0904 commented Aug 17, 2018

Hey @KyleAMathews does it need to be import { navigate } from "gatsby" instead of import { navigate } from "@reach/router" at https://next.gatsbyjs.org/docs/migrating-from-v1-to-v2/#a-history-prop-is-no-longer-passed-to-page-components ?

Ohh no I got confused because of Link component imported from gatsby instead of react-router so I thought that must've been the case.

@jorgegonzalez
Copy link

I think activeClassName no longer works for the root route (/) until you navigate to it from a different route.

@haxzie-xx
Copy link

@jorgegonzalez tried exact={true} ? This worked for me.

porfirioribeiro pushed a commit to porfirioribeiro/gatsby that referenced this pull request Aug 22, 2018
* Get @reach/router working probably in development

* Moer stuff working

* Don't support to as an object

* Add back support for activeClassName & activeStyle

* Fix path for RouteHandlers

* Pull in parse-path util from react-router

* remove console.logs and add TODO

* Remove now unused webpack rules to trim down react-router

* Some fixes from merge

* Fix problems identified in review earlier

* Remove old typescript definitions

* Restore and update the <Link> documentation for v2/@reach/router

I also added it to the API reference section — which seemed the right
place for it. @shannonbux agree?

* Also set the className when the site is active per @pieh's advice

* Upgrade client-only-paths example site

* Upgrade simple-auth example site

* Fix lint errors

* Migration docs

* Note that can't use relative routes w/ @reach/router

* Fix/remove tests that are irrelevant now

* Fix imports

* Use v2 version of children for layout

* mini typos

* Document that history prop no longer passed to page components
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

Investigate using Reach Router
9 participants