Skip to content

Commit f509b1f

Browse files
authored
Add v4 FAQ
1 parent bb3e264 commit f509b1f

File tree

1 file changed

+147
-0
lines changed

1 file changed

+147
-0
lines changed

README.md

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,153 @@ You can find the library on `window.ReactRouter`.
3939

4040
Please read [our docs here](https://react-router-website-xvufzcovng.now.sh/).
4141

42+
## v4 FAQ
43+
44+
### Why the huge change? (AGAIN?!)
45+
46+
**tl;dr** Declarative Composability.
47+
48+
We've never been this excited about React Router. Like you, we've
49+
learned a lot about React since we first picked it up. We built a Router
50+
the best we knew how along the way. What we've learned most is that we
51+
love React because of its **declarative composability**.
52+
53+
As we looked at the router, it didn't work that way because of the
54+
static route configuration. You couldn't even wrap a Route!
55+
56+
```js
57+
// NOPE!
58+
const CoolRoute = (props) => <Route {...props} cool={true}/>
59+
```
60+
61+
For apps to participate in rendering of route components, we had to
62+
create APIs we were never actually comfortable with, like `<Router
63+
createElement render>` and `createRouterMiddleware`. We took
64+
`createElement` away from you and had to give it back!
65+
66+
We had to recreate the lifecycle hooks with `onEnter`, `onLeave`, and
67+
`onChange`. React already has `componentWillMount`,
68+
`componentWillReceiveProps` and `componentWillUnmount`.
69+
70+
Route configs described your view hierarchy. Turns out, React components
71+
already describe view hierarchy.
72+
73+
To code-split, we had to introduce `getComponent` and `getChildRoutes`.
74+
Hot module replacement libs had to do specific hacks for routes to work.
75+
The list goes on and on.
76+
77+
React Router was not a React router, it was a routing framework for
78+
React. An accidental framework with APIs that were not only redundant
79+
with React, but incredibly difficult to build an ecosystem around.
80+
81+
What did we do? We took everything we've learned and love about React
82+
(and we're still learning!) and applied it to routing. It started with
83+
the quest to actually render a `<Route>` (we used to just strip their
84+
props). It ended with removing the idea of routes completely (surprised
85+
us too) and a completely component based API, which actually means no
86+
API at all.
87+
88+
You control routing by rendering components and passing props. Finally,
89+
we have a solid base for us and others to build an ecosystem on top of.
90+
91+
In other words, it's Just React™ and you're going to love it.
92+
93+
### How long until another huge API overhaul?
94+
95+
We know things have been rocky. Our previous API was fighting against
96+
React, causing a ton of churn. With v4, our only API is components that
97+
receive props, so, it's hard to imagine a big change again. Now that
98+
we're embracing (not fighting) React's declarative composability, we
99+
think this API will last as long as React itself, because that's all it
100+
is.
101+
102+
Not only that, but we're excited to create and encourage building an
103+
ecosystem of addons to this stable base.
104+
105+
### Why did you get rid of feature [x]?
106+
107+
We've been pulled a lot of directions with bleeding edge use-cases that
108+
nobody really has generic answers for: server rendering, code-splitting
109+
while avoiding waterfalls, anticipating streamed server rendering, loading
110+
data before rendering anything, etc. We unconciously tried to solve this
111+
stuff when all we really want to be doing is keeping rendered UI in sync
112+
with the url. That's our scope of responsibility.
113+
114+
By using components as our only API, features we had that are important
115+
to you can be implemented on top of these components.
116+
117+
We will be creating some addons and hope to see others too.
118+
119+
### What about scrolling?
120+
121+
We have some code close to being published that will manage the scroll
122+
positions of window and individual elements.
123+
124+
### What about Redux?
125+
126+
We have a `<ControlledRouter>` close to being published that makes redux
127+
integration with React Router the same as ... uh ... integrating an
128+
`<input>` with Redux.
129+
130+
### What about route transition hooks? (example needed)
131+
132+
Because we are just components, you have the component lifecycle as
133+
transition hooks. They are completely parallel. The only difference is
134+
that the route transition hooks could be asynchronous. The problem with
135+
that was you weren't in the render lifecycle so you couldn't use React
136+
to indicate to the user something was happening.
137+
138+
```js
139+
<Route onEnter={(_, cb) => {
140+
loadStuffForever(() => {
141+
// WHAT IS THE USER SEEING RIGHT NOW?
142+
cb()
143+
})
144+
}}/>
145+
```
146+
147+
One use case was loading data and waiting to render the next screen
148+
until the data landed. With a component, you can save the previous
149+
children, render them while loading, and then render your new children
150+
when you're done. We'll have an example of this eventually.
151+
152+
### I liked seeing all my routes in one place, now what?
153+
154+
Check out the "Route Config" example.
155+
156+
### I want to load data before rendering, now what?
157+
158+
See below
159+
160+
### The route config is important to the ecosystem, now what?
161+
162+
We will be providing a package that will prescribe a route config for
163+
others to build on. It will also provide a function that will match a
164+
location to the route config and return the routes that match, allowing
165+
you to do things (like data loading) before an initial render.
166+
167+
### What about upgrading?
168+
169+
We believe very strongly in iterative migration, not rewrites, for
170+
applications. We are working on a migration guide, but the basic
171+
strategy is that both versions will be runnable in tandem (due to npm
172+
limitations, we'll publish the previous version seperately so both can
173+
be installed).
174+
175+
You will be able to take routes one-by-one and migrate them to the new
176+
API. Additionally, the config addon mentioned above may help out here.
177+
178+
### We're Pumped!
179+
180+
We've received a ton of great feedback from people we really admire in
181+
the React community so we know we've found something special that's a
182+
bit unprecendented in the world of UI routing.
183+
184+
We've never been more excited about React Router. It's no longer a
185+
router for React, it is truly a React Router.
186+
187+
188+
42189
## Thanks
43190

44191
Thanks to [our sponsors](/SPONSORS.md) for supporting the development of React Router.

0 commit comments

Comments
 (0)