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
Copy file name to clipboardExpand all lines: packages/react-router/docs/guides/migrating.md
+21-1Lines changed: 21 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,6 +10,8 @@ React Router v4 is a complete rewrite, so there is not a simple migration path.
10
10
*[Routes](#routes)
11
11
*[Nesting Routes](#nesting-routes)
12
12
*[on* properties](#on-properties)
13
+
*[Optional Parameters](#optional-parameters)
14
+
*[Query Strings](#query-strings)
13
15
*[Switch](#switch)
14
16
*[Redirect](#redirect)
15
17
*[PatternUtils](#patternutils)
@@ -121,6 +123,20 @@ React Router v3 provides `onEnter`, `onUpdate`, and `onLeave` methods. These wer
121
123
122
124
With v4, you should use the lifecycle methods of the component rendered by a `<Route>`. Instead of `onEnter`, you would use `componentDidMount` or `componentWillMount`. Where you would use `onUpdate`, you can use `componentDidUpdate` or `componentWillUpdate` (or possibly `componentWillReceiveProps`). `onLeave` can be replaced with `componentWillUnmount`.
123
125
126
+
### Optional Parameters
127
+
128
+
In v3, parameters were made optional with parentheses: `path="/entity/:entityId(/:parentId)"`
129
+
130
+
In v4, the syntax is changed to a trailing question mark: `path="/entity/:entityId/:parentId?"`
131
+
132
+
### Query Strings
133
+
134
+
In v4, there is no parsing done on query strings. The unparsed query string is available on the `location.search` property.
135
+
136
+
The [qhistory](https://github.com/pshrmn/qhistory) library can provide this functionality if it is necessary for your application.
137
+
138
+
Read more regarding intentions for this change and possible solutions in [this issue](https://github.com/ReactTraining/react-router/issues/4410).
139
+
124
140
### `<Switch>`
125
141
126
142
In v3, you could specify a number of child routes, and only the first one that matched would be rendered.
In v4, you can achieve the same functionality using the [compile](https://github.com/pillarjs/path-to-regexp/tree/v1.7.0#compile-reverse-path-to-regexp) function in [`path-to-regexp@^1.7.0`](https://github.com/pillarjs/path-to-regexp/tree/v1.7.0).
229
+
In v4, you can achieve the same functionality using the [`compile`](https://github.com/pillarjs/path-to-regexp/tree/v1.7.0#compile-reverse-path-to-regexp) function in [`path-to-regexp@^1.7.0`](https://github.com/pillarjs/path-to-regexp/tree/v1.7.0).
The `getParamNames` functionality can be achieved using the [`parse`](https://github.com/pillarjs/path-to-regexp/tree/v1.7.0#parse) function in [`path-to-regexp@^1.7.0`](https://github.com/pillarjs/path-to-regexp/tree/v1.7.0).
0 commit comments