You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
37
39
38
40
```js
39
41
<Router>
@@ -52,16 +54,36 @@ Route matching happens in the order they are defined (think `if/elseif` statemen
52
54
```
53
55
54
56
55
-
### "Required prop was not specified" on route components
57
+
### Parent path does not show as active
56
58
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:
58
60
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.
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:
61
69
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
+
```
63
78
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.
65
87
66
88
67
89
### 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:
71
93
- Define additional values on `<Route>` or the plain route. This will make those values available on `this.props.route` on route components.
72
94
- Pass in a `createElement` handler to `<Router>` or `<RouterContext>`. This will allow you to inject additional props into route elements at creation time.
73
95
- 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