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
When the router is ready to render a branch of route components, it will use this function to create the elements. You may want to take control of creating the elements when you're using some sort of data abstraction, like setting up subscriptions to stores, or passing in some sort of application module to each component via props.
63
63
64
-
```jsx
64
+
```js
65
65
<Router createElement={createElement} />
66
66
67
67
// default behavior
@@ -140,7 +140,7 @@ You can also pass props you'd like to be on the `<a>` such as a `title`, `id`, `
140
140
#### Example
141
141
Given a route like `<Route path="/users/:userId" />`:
// Given a `wrapperInstance` that is of type `WrapperComponent`:
@@ -186,7 +186,7 @@ Contains data and methods relevant to routing. Most useful for imperatively tran
186
186
##### `push(pathOrLoc)`
187
187
Transitions to a new URL, adding a new entry in the browser history.
188
188
189
-
```jsx
189
+
```js
190
190
router.push('/users/12')
191
191
192
192
// or with a location descriptor object
@@ -256,7 +256,7 @@ If left undefined, the router will try to match the child routes.
256
256
A single component to be rendered when the route matches the URL. It can
257
257
be rendered by the parent route component with `this.props.children`.
258
258
259
-
```jsx
259
+
```js
260
260
constroutes= (
261
261
<Route path="/" component={App}>
262
262
<Route path="groups" component={Groups} />
@@ -279,7 +279,7 @@ class App extends React.Component {
279
279
##### `components`
280
280
Routes can define one or more named components as an object of `[name]: component` pairs to be rendered when the path matches the URL. They can be rendered by the parent route component with `this.props[name]`.
281
281
282
-
```jsx
282
+
```js
283
283
// Think of it outside the context of the router - if you had pluggable
284
284
// portions of your `render`, you might do it like this:
@@ -403,7 +403,7 @@ Same as `childRoutes` but asynchronous and receives `partialNextState`. Useful f
403
403
###### `callback` signature
404
404
`cb(err, routesArray)`
405
405
406
-
```jsx
406
+
```js
407
407
let myRoute = {
408
408
path:'course/:courseId',
409
409
childRoutes: [
@@ -450,7 +450,7 @@ Same as `indexRoute`, but asynchronous and receives `partialNextState`. As with
450
450
###### `callback` signature
451
451
`cb(err, route)`
452
452
453
-
```jsx
453
+
```js
454
454
// For example:
455
455
let myIndexRoute = {
456
456
component: MyIndex
@@ -486,7 +486,7 @@ The path you want to redirect to.
486
486
##### `query`
487
487
By default, the query parameters will just pass through but you can specify them if you need to.
488
488
489
-
```jsx
489
+
```js
490
490
// Say we want to change from `/profile/123` to `/about/123`
491
491
// and redirect `/get-in-touch` to `/contact`
492
492
<Route component={App}>
@@ -498,7 +498,7 @@ By default, the query parameters will just pass through but you can specify them
498
498
499
499
Note that the `<Redirect>` can be placed anywhere in the route hierarchy, though [normal precedence](/docs/guides/RouteMatching.md#precedence) rules apply. If you'd prefer the redirects to be next to their respective routes, the `from` path will match the same as a regular route `path`.
500
500
501
-
```jsx
501
+
```js
502
502
<Route path="course/:courseId">
503
503
<Route path="dashboard"/>
504
504
{/* /course/123/home -> /course/123/dashboard */}
@@ -549,7 +549,7 @@ A subset of `this.props.params` that were directly specified in this component's
549
549
The matched child route element to be rendered. If the route has [named components](/docs/API.md#named-components) then this will be undefined, and the components will instead be available as direct properties on `this.props`.
550
550
551
551
##### Example
552
-
```jsx
552
+
```js
553
553
render((
554
554
<Router>
555
555
<Route path="/" component={App}>
@@ -577,7 +577,7 @@ class App extends React.Component {
577
577
When a route has one or more named components, the child elements are available by name on `this.props`. In this case `this.props.children` will be undefined. All route components can participate in the nesting.
Copy file name to clipboardexpand all lines: docs/Glossary.md
+20-20
Original file line number
Diff line number
Diff line change
@@ -27,7 +27,7 @@ This is a glossary of common terms used in the React Router codebase and documen
27
27
28
28
## Action
29
29
30
-
```jsx
30
+
```js
31
31
type Action ='PUSH'|'REPLACE'|'POP';
32
32
```
33
33
@@ -39,15 +39,15 @@ An *action* describes the type of change to a URL. Possible values are:
39
39
40
40
## Component
41
41
42
-
```jsx
42
+
```js
43
43
type Component = ReactClass | string;
44
44
```
45
45
46
46
A *component* is a React component class or a string (e.g. "div"). Basically, it's anything that can be used as the first argument to [`React.createElement`](https://facebook.github.io/react/docs/top-level-api.html#react.createelement).
47
47
48
48
## EnterHook
49
49
50
-
```jsx
50
+
```js
51
51
type EnterHook= (nextState:RouterState, replace:RedirectFunction, callback?:Function) => any;
52
52
```
53
53
@@ -65,15 +65,15 @@ A *hash* is a string that represents the hash portion of the URL. It is synonymo
65
65
66
66
## LeaveHook
67
67
68
-
```jsx
68
+
```js
69
69
type LeaveHook= (prevState:RouterState) => any;
70
70
```
71
71
72
72
A *leave hook* is a user-defined function that is called when a route is about to be unmounted. It receives the previous [router state](#routerstate) as its first argument.
73
73
74
74
## Location
75
75
76
-
```jsx
76
+
```js
77
77
type Location= {
78
78
pathname: Pathname;
79
79
search: QueryString;
@@ -108,15 +108,15 @@ You can read more about location descriptors in [the `history` docs](https://git
108
108
109
109
## LocationKey
110
110
111
-
```jsx
111
+
```js
112
112
type LocationKey = string;
113
113
```
114
114
115
115
A *location key* is a string that is unique to a particular [`location`](#location). It is the one piece of data that most accurately answers the question "Where am I?".
116
116
117
117
## LocationState
118
118
119
-
```jsx
119
+
```js
120
120
type LocationState =?Object;
121
121
```
122
122
@@ -129,55 +129,55 @@ This type gets its name from the first argument to HTML5's [`pushState`][pushSta
129
129
130
130
## Params
131
131
132
-
```jsx
132
+
```js
133
133
type Params =Object;
134
134
```
135
135
136
136
The word *params* refers to an object of key/value pairs that were parsed out of the original URL's [pathname](#pathname). The values of this object are typically strings, unless there is more than one param with the same name in which case the value is an array.
137
137
138
138
## Path
139
139
140
-
```jsx
140
+
```js
141
141
type Path = Pathname + QueryString + Hash;
142
142
```
143
143
144
144
A *path* represents a URL path.
145
145
146
146
## Pathname
147
147
148
-
```jsx
148
+
```js
149
149
type Pathname = string;
150
150
```
151
151
152
152
A *pathname* is the portion of a URL that describes a hierarchical path, including the preceding `/`. For example, in `http://example.com/the/path?the=query`, `/the/path` is the pathname. It is synonymous with `window.location.pathname` in web browsers.
153
153
154
154
## Query
155
155
156
-
```jsx
156
+
```js
157
157
type Query = Object;
158
158
```
159
159
160
160
A*query* is the parsed version of a [query string](#querystring).
161
161
162
162
## QueryString
163
163
164
-
```jsx
164
+
```js
165
165
type QueryString = string;
166
166
```
167
167
168
168
A*query string* is the portion of the URL that follows the [pathname](#pathname), including any preceding `?`. For example, in`http://example.com/the/path?the=query`, `?the=query` is the query string. It is synonymous with`window.location.search`in web browsers.
A*redirect function* is used in [`onEnter` hooks](#enterhook) to trigger a transition to a new URL.
177
177
178
178
## Route
179
179
180
-
```jsx
180
+
```js
181
181
type Route = {
182
182
component: RouteComponent;
183
183
path:?RoutePattern;
@@ -192,7 +192,7 @@ It may help to think of a route as an "entry point" into your UI. You don't need
192
192
193
193
## RouteComponent
194
194
195
-
```jsx
195
+
```js
196
196
type RouteComponent = Component;
197
197
```
198
198
@@ -208,23 +208,23 @@ Route components should generally be component classes rather than strings. This
208
208
209
209
## RouteConfig
210
210
211
-
```jsx
211
+
```js
212
212
type RouteConfig =Array<Route>;
213
213
```
214
214
215
215
A *route config* is an array of [route](#route)s that specifies the order in which routes should be tried when the router attempts to match a URL.
216
216
217
217
## RouteHook
218
218
219
-
```jsx
219
+
```js
220
220
type RouteHook= (nextLocation?:Location) => any;
221
221
```
222
222
223
223
A *route hook* is a function that is used to prevent the user from leaving a route. On normal transitions, it receives the next [location](#location) as an argument and must either `returnfalse` to cancel the transition or `return` a prompt message to show the user. When invoked during the `beforeunload` event in web browsers, it does not receive any arguments and must `return` a prompt message to cancel the transition.
224
224
225
225
## RoutePattern
226
226
227
-
```jsx
227
+
```js
228
228
type RoutePattern = string;
229
229
```
230
230
@@ -239,7 +239,7 @@ Route patterns are relative to the pattern of the parent route unless they begin
239
239
240
240
## Router
241
241
242
-
```jsx
242
+
```js
243
243
type Router = {
244
244
push(location: LocationDescriptor) =>void;
245
245
replace(location: LocationDescriptor) =>void;
@@ -255,7 +255,7 @@ A *router* object allows for procedural manipulation of the routing state.
Copy file name to clipboardexpand all lines: docs/Introduction.md
+5-5
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,7 @@ To illustrate the problems React Router is going to solve for you, let's build a
6
6
7
7
### Without React Router
8
8
9
-
```jsx
9
+
```js
10
10
importReactfrom'react'
11
11
import { render } from'react-dom'
12
12
@@ -101,7 +101,7 @@ We'd have to make our URL parsing a lot smarter, and we would end up with a lot
101
101
102
102
Let's refactor our app to use React Router.
103
103
104
-
```jsx
104
+
```js
105
105
importReactfrom'react'
106
106
import { render } from'react-dom'
107
107
@@ -148,7 +148,7 @@ React Router knows how to build nested UI for us, so we don't have to manually f
148
148
149
149
Internally, the router converts your `<Route>` element hierarchy to a [route config](/docs/Glossary.md#routeconfig). But if you're not digging the JSX you can use plain objects instead:
Alright, now we're ready to nest the inbox messages inside the inbox UI.
168
168
169
-
```jsx
169
+
```js
170
170
// Make a new component to render inside of Inbox
171
171
constMessage=React.createClass({
172
172
render() {
@@ -228,7 +228,7 @@ And visits to `/inbox` will build this:
228
228
229
229
We're going to need to know something about the message in order to fetch it from the server. Route components get some useful properties injected into them when you render, particularly the parameters from the dynamic segment of your path. In our case, `:id`.
0 commit comments