Skip to content

Commit 61ee087

Browse files
committed
Merge pull request #3396 from reactjs/troubleshooting-isActive
Add section on isActive to troubleshooting guide
2 parents 0a65cfd + a89b606 commit 61ee087

File tree

1 file changed

+33
-6
lines changed

1 file changed

+33
-6
lines changed

docs/Troubleshooting.md

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const Component = withRouter(
1212
)
1313
```
1414

15+
1516
### Getting the previous location
1617

1718
```js
@@ -31,9 +32,10 @@ const App = React.createClass({
3132
})
3233
```
3334

35+
3436
### Component won't render
3537

36-
Route matching happens in the order they are defined (think `if/elseif` statement). In this case, `/about/me` will show the `<UserPage>` component because `/about/me` matches the first route. You need to reorder your routes if this happens. `<About>` will never be reachable:
38+
Route matching happens in the order they are defined (think `if/else if` statement). In this case, `/about/me` will show the `<UserPage>` component because `/about/me` matches the first route. You need to reorder your routes if this happens. `<About>` will never be reachable:
3739

3840
```js
3941
<Router>
@@ -52,16 +54,36 @@ Route matching happens in the order they are defined (think `if/elseif` statemen
5254
```
5355

5456

55-
### "Required prop was not specified" on route components
57+
### Parent path does not show as active
5658

57-
You might see this if you are using `React.cloneElement` to inject props into route components from their parents. If you see this, remove `isRequired` from `propTypes` for those props. This happens because React validates `propTypes` when the element is created rather than when it is mounted. For more details, see [facebook/react#4494](https://github.com/facebook/react/issues/4494#issuecomment-125068868).
59+
If your routes look like:
5860

59-
You should generally attempt to use this pattern as sparingly as possible. In general, it's best practice to minimize data dependencies between route components.
61+
```js
62+
<Route path="/">
63+
<Route path="widgets" component={WidgetList} />
64+
<Route path="widgets/:widgetId" component={Widget} />
65+
</Route>
66+
```
6067

68+
Then the path `/widgets` will not be considered active when the current path is something like `/widgets/3`. This is because React Router looks at parent _routes_ rather than parent _paths_ to determine active state. To make the path `/widgets` active when the current path is `/widgets/3`, you need to declare your routes as:
6169

62-
### `<noscript>` with server-side rendering and async routes
70+
```js
71+
<Route path="/">
72+
<Route path="widgets">
73+
<IndexRoute component={WidgetList} />
74+
<Route path=":widgetId" component={Widget} />
75+
</Route>
76+
</Route>
77+
```
6378

64-
Use `match({ history, routes })` on the client side. See [the server rendering guide](guides/ServerRendering.md#async-routes).
79+
As an additional benefit, this also removes the duplication in declaring route paths.
80+
81+
82+
### "Required prop was not specified" on route components
83+
84+
You might see this if you are using `React.cloneElement` to inject props into route components from their parents. If you see this, remove `isRequired` from `propTypes` for those props. This happens because React validates `propTypes` when the element is created rather than when it is mounted. For more details, see [facebook/react#4494](https://github.com/facebook/react/issues/4494#issuecomment-125068868).
85+
86+
You should generally attempt to use this pattern as sparingly as possible. In general, it's best practice to minimize data dependencies between route components.
6587

6688

6789
### Passing additional values into route components
@@ -71,3 +93,8 @@ There are multiple ways to do this depending on what you want to do. You can:
7193
- Define additional values on `<Route>` or the plain route. This will make those values available on `this.props.route` on route components.
7294
- Pass in a `createElement` handler to `<Router>` or `<RouterContext>`. This will allow you to inject additional props into route elements at creation time.
7395
- Define a top-level component above `<Router>` or `<RouterContext>` that exports additional values via `getChildContext`, then access them via context from rendered components.
96+
97+
98+
### `<noscript>` with server-side rendering and async routes
99+
100+
Use `match({ history, routes })` on the client side. See [the server rendering guide](guides/ServerRendering.md#async-routes).

0 commit comments

Comments
 (0)