Skip to content

Commit 3076dca

Browse files
committed
Call getComponent with nextState instead of location
1 parent d4f8d3c commit 3076dca

File tree

17 files changed

+119
-40
lines changed

17 files changed

+119
-40
lines changed

docs/API.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ A function used to convert an object from [`<Link>`](#link)s or calls to
8484
A function used to convert a query string into an object that gets passed to route component props.
8585

8686
##### `onError(error)`
87-
While the router is matching, errors may bubble up, here is your opportunity to catch and deal with them. Typically these will come from async features like [`route.getComponents`](#getcomponentslocation-callback), [`route.getIndexRoute`](#getindexroutelocation-callback), and [`route.getChildRoutes`](#getchildrouteslocation-callback).
87+
While the router is matching, errors may bubble up, here is your opportunity to catch and deal with them. Typically these will come from async features like [`route.getComponents`](#getcomponentsnextstate-callback), [`route.getIndexRoute`](#getindexroutelocation-callback), and [`route.getChildRoutes`](#getchildrouteslocation-callback).
8888

8989
##### `onUpdate()`
9090
Called whenever the router updates its state in response to URL changes.
@@ -300,29 +300,29 @@ class Users extends React.Component {
300300
}
301301
```
302302

303-
##### `getComponent(location, callback)`
303+
##### `getComponent(nextState, callback)`
304304
Same as `component` but asynchronous, useful for
305305
code-splitting.
306306

307307
###### `callback` signature
308308
`cb(err, component)`
309309

310310
```js
311-
<Route path="courses/:courseId" getComponent={(location, cb) => {
311+
<Route path="courses/:courseId" getComponent={(nextState, cb) => {
312312
// do asynchronous stuff to find the components
313313
cb(null, Course)
314314
}} />
315315
```
316316

317-
##### `getComponents(location, callback)`
317+
##### `getComponents(nextState, callback)`
318318
Same as `components` but asynchronous, useful for
319319
code-splitting.
320320

321321
###### `callback` signature
322322
`cb(err, components)`
323323

324324
```js
325-
<Route path="courses/:courseId" getComponents={(location, cb) => {
325+
<Route path="courses/:courseId" getComponents={(nextState, cb) => {
326326
// do asynchronous stuff to find the components
327327
cb(null, {sidebar: CourseSidebar, content: Course})
328328
}} />

docs/guides/DynamicRouting.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ A router is the perfect place to handle code splitting: it's responsible for set
1010

1111
React Router does all of its [path matching](/docs/guides/RouteMatching.md) and component fetching asynchronously, which allows you to not only load up the components lazily, *but also lazily load the route configuration*. You really only need one route definition in your initial bundle, the router can resolve the rest on demand.
1212

13-
Routes may define [`getChildRoutes`](/docs/API.md#getchildrouteslocation-callback), [`getIndexRoute`](/docs/API.md#getindexroutelocation-callback), and [`getComponents`](/docs/API.md#getcomponentslocation-callback) methods. These are asynchronous and only called when needed. We call it "gradual matching". React Router will gradually match the URL and fetch only the amount of route configuration and components it needs to match the URL and render.
13+
Routes may define [`getChildRoutes`](/docs/API.md#getchildrouteslocation-callback), [`getIndexRoute`](/docs/API.md#getindexroutelocation-callback), and [`getComponents`](/docs/API.md#getcomponentsnextstate-callback) methods. These are asynchronous and only called when needed. We call it "gradual matching". React Router will gradually match the URL and fetch only the amount of route configuration and components it needs to match the URL and render.
1414

1515
Coupled with a smart code splitting tool like [webpack](http://webpack.github.io/), a once tiresome architecture is now simple and declarative.
1616

@@ -36,7 +36,7 @@ const CourseRoute = {
3636
})
3737
},
3838

39-
getComponents(location, callback) {
39+
getComponents(nextState, callback) {
4040
require.ensure([], function (require) {
4141
callback(null, require('./components/Course'))
4242
})

examples/auth-with-shared-root/config/routes.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ export default {
1919
component: require('../components/App'),
2020
childRoutes: [
2121
{ path: '/logout',
22-
getComponent: (location, cb) => {
22+
getComponent: (nextState, cb) => {
2323
require.ensure([], (require) => {
2424
cb(null, require('../components/Logout'))
2525
})
2626
}
2727
},
2828
{ path: '/about',
29-
getComponent: (location, cb) => {
29+
getComponent: (nextState, cb) => {
3030
require.ensure([], (require) => {
3131
cb(null, require('../components/About'))
3232
})
@@ -38,7 +38,7 @@ export default {
3838
// Unauthenticated routes
3939
// Redirect to dashboard if user is already logged in
4040
{ path: '/login',
41-
getComponent: (location, cb) => {
41+
getComponent: (nextState, cb) => {
4242
require.ensure([], (require) => {
4343
cb(null, require('../components/Login'))
4444
})
@@ -52,7 +52,7 @@ export default {
5252
childRoutes: [
5353
// Protected routes that don't share the dashboard UI
5454
{ path: '/user/:id',
55-
getComponent: (location, cb) => {
55+
getComponent: (nextState, cb) => {
5656
require.ensure([], (require) => {
5757
cb(null, require('../components/User'))
5858
})
@@ -63,7 +63,7 @@ export default {
6363
},
6464

6565
{ path: '/',
66-
getComponent: (location, cb) => {
66+
getComponent: (nextState, cb) => {
6767
// Share the path
6868
// Dynamically load the correct component
6969
if (auth.loggedIn()) {
@@ -76,7 +76,7 @@ export default {
7676
})
7777
},
7878
indexRoute: {
79-
getComponent: (location, cb) => {
79+
getComponent: (nextState, cb) => {
8080
// Only load if we're logged in
8181
if (auth.loggedIn()) {
8282
return require.ensure([], (require) => {
@@ -91,7 +91,7 @@ export default {
9191
childRoutes: [
9292
// Protected nested routes for the dashboard
9393
{ path: '/page2',
94-
getComponent: (location, cb) => {
94+
getComponent: (nextState, cb) => {
9595
require.ensure([], (require) => {
9696
cb(null, require('../components/PageTwo'))
9797
})

examples/huge-apps/routes/Calendar/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module.exports = {
22
path: 'calendar',
3-
getComponent(location, cb) {
3+
getComponent(nextState, cb) {
44
require.ensure([], (require) => {
55
cb(null, require('./components/Calendar'))
66
})

examples/huge-apps/routes/Course/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ module.exports = {
1111
})
1212
},
1313

14-
getComponent(location, cb) {
14+
getComponent(nextState, cb) {
1515
require.ensure([], (require) => {
1616
cb(null, require('./components/Course'))
1717
})

examples/huge-apps/routes/Course/routes/Announcements/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ module.exports = {
99
})
1010
},
1111

12-
getComponents(location, cb) {
12+
getComponents(nextState, cb) {
1313
require.ensure([], (require) => {
1414
cb(null, {
1515
sidebar: require('./components/Sidebar'),

examples/huge-apps/routes/Course/routes/Announcements/routes/Announcement/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module.exports = {
22
path: ':announcementId',
33

4-
getComponent(location, cb) {
4+
getComponent(nextState, cb) {
55
require.ensure([], (require) => {
66
cb(null, require('./components/Announcement'))
77
})

examples/huge-apps/routes/Course/routes/Assignments/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ module.exports = {
99
})
1010
},
1111

12-
getComponents(location, cb) {
12+
getComponents(nextState, cb) {
1313
require.ensure([], (require) => {
1414
cb(null, {
1515
sidebar: require('./components/Sidebar'),

examples/huge-apps/routes/Course/routes/Assignments/routes/Assignment/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module.exports = {
22
path: ':assignmentId',
3-
getComponent(location, cb) {
3+
getComponent(nextState, cb) {
44
require.ensure([], (require) => {
55
cb(null, require('./components/Assignment'))
66
})

examples/huge-apps/routes/Course/routes/Grades/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module.exports = {
22
path: 'grades',
3-
getComponent(location, cb) {
3+
getComponent(nextState, cb) {
44
require.ensure([], (require) => {
55
cb(null, require('./components/Grades'))
66
})

0 commit comments

Comments
 (0)