Skip to content

Commit 3be4f54

Browse files
committed
Merge pull request #796 from uberllama/master
Added documentation for skipping dynamic segment transition optimization
2 parents b5cd3d0 + f66c528 commit 3be4f54

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

docs/guides/overview.md

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,11 +352,37 @@ Important Note About Dynamic Segments
352352
If you have dynamic segments in your URL, a transition from `/users/123`
353353
to `/users/456` does not call `getInitialState`, `componentWillMount`, `componentWillUnmount` or `componentDidMount`. If you are using those lifecycle hooks to fetch
354354
data and set state, you will also need to implement
355-
`componentWillReceiveProps` on your handler, just like any other
355+
`componentWillReceiveProps` on your handler and its stateful children, just like any other
356356
component whose props are changing. This way you can leverage the
357357
performance of the React DOM diff algorithm. Look at the `Contact`
358358
handler [in the `master-detail` example](https://github.com/rackt/react-router/blob/master/examples/master-detail/app.js).
359359

360+
If you would rather force route handlers to re-mount when transitioning between dynamic segments, you can assign a unique key to your route handler component to bypass this optimization:
361+
362+
```js
363+
// assuming App is top-level route
364+
var App = React.createClass({
365+
366+
mixins: [Router.State],
367+
368+
getHandlerKey: function () {
369+
var childDepth = 1;
370+
var key = this.getRoutes()[childDepth].name;
371+
var id = this.getParams().id;
372+
if (id) { key += id; }
373+
return key;
374+
},
375+
376+
render: function () {
377+
return (
378+
<div>
379+
<RouteHandler key={this.getHandlerKey()} />
380+
</div>
381+
);
382+
}
383+
});
384+
```
385+
360386
Scrolling
361387
---------
362388

0 commit comments

Comments
 (0)