Skip to content

Commit 759b4b1

Browse files
committed
Improve syntax highlighting
1 parent 5ca7958 commit 759b4b1

20 files changed

+122
-122
lines changed

docs/API.md

+17-17
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,15 @@ Alias for `children`.
5353
##### `history`
5454
The history the router should listen to. Typically `browserHistory` or `hashHistory`.
5555

56-
```jsx
56+
```js
5757
import { browserHistory } from 'react-router'
5858
ReactDOM.render(<Router history={browserHistory} />, el)
5959
```
6060

6161
##### `createElement(Component, props)`
6262
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.
6363

64-
```jsx
64+
```js
6565
<Router createElement={createElement} />
6666

6767
// default behavior
@@ -140,7 +140,7 @@ You can also pass props you'd like to be on the `<a>` such as a `title`, `id`, `
140140
#### Example
141141
Given a route like `<Route path="/users/:userId" />`:
142142

143-
```jsx
143+
```js
144144
<Link to={`/users/${user.id}`} activeClassName="active">{user.name}</Link>
145145
// becomes one of these depending on your History and if the route is
146146
// active
@@ -167,7 +167,7 @@ You can explicit specify `router` as a prop to the wrapper component to override
167167
##### `withRef`
168168
If `true`, the wrapper component attaches a ref to the wrapped component, which can then be accessed via `getWrappedInstance`.
169169

170-
```jsx
170+
```js
171171
const WrapperComponent = withRouter(MyComponent, { withRef: true })
172172

173173
// Given a `wrapperInstance` that is of type `WrapperComponent`:
@@ -186,7 +186,7 @@ Contains data and methods relevant to routing. Most useful for imperatively tran
186186
##### `push(pathOrLoc)`
187187
Transitions to a new URL, adding a new entry in the browser history.
188188

189-
```jsx
189+
```js
190190
router.push('/users/12')
191191

192192
// or with a location descriptor object
@@ -256,7 +256,7 @@ If left undefined, the router will try to match the child routes.
256256
A single component to be rendered when the route matches the URL. It can
257257
be rendered by the parent route component with `this.props.children`.
258258

259-
```jsx
259+
```js
260260
const routes = (
261261
<Route path="/" component={App}>
262262
<Route path="groups" component={Groups} />
@@ -279,7 +279,7 @@ class App extends React.Component {
279279
##### `components`
280280
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]`.
281281

282-
```jsx
282+
```js
283283
// Think of it outside the context of the router - if you had pluggable
284284
// portions of your `render`, you might do it like this:
285285
// <App main={<Users />} sidebar={<UsersSidebar />} />
@@ -330,7 +330,7 @@ Same as `component` but asynchronous, useful for code-splitting.
330330
###### `callback` signature
331331
`cb(err, component)`
332332

333-
```jsx
333+
```js
334334
<Route path="courses/:courseId" getComponent={(nextState, cb) => {
335335
// do asynchronous stuff to find the components
336336
cb(null, Course)
@@ -344,7 +344,7 @@ code-splitting.
344344
###### `callback` signature
345345
`cb(err, components)`
346346

347-
```jsx
347+
```js
348348
<Route path="courses/:courseId" getComponents={(nextState, cb) => {
349349
// do asynchronous stuff to find the components
350350
cb(null, {sidebar: CourseSidebar, content: Course})
@@ -362,7 +362,7 @@ If `callback` is listed as a 3rd argument, this hook will run asynchronously, an
362362
###### `callback` signature
363363
`cb(err)`
364364

365-
```jsx
365+
```js
366366
const userIsInATeam = (nextState, replace, callback) => {
367367
fetch(...)
368368
.then(response = response.json())
@@ -403,7 +403,7 @@ Same as `childRoutes` but asynchronous and receives `partialNextState`. Useful f
403403
###### `callback` signature
404404
`cb(err, routesArray)`
405405

406-
```jsx
406+
```js
407407
let myRoute = {
408408
path: 'course/:courseId',
409409
childRoutes: [
@@ -450,7 +450,7 @@ Same as `indexRoute`, but asynchronous and receives `partialNextState`. As with
450450
###### `callback` signature
451451
`cb(err, route)`
452452

453-
```jsx
453+
```js
454454
// For example:
455455
let myIndexRoute = {
456456
component: MyIndex
@@ -486,7 +486,7 @@ The path you want to redirect to.
486486
##### `query`
487487
By default, the query parameters will just pass through but you can specify them if you need to.
488488

489-
```jsx
489+
```js
490490
// Say we want to change from `/profile/123` to `/about/123`
491491
// and redirect `/get-in-touch` to `/contact`
492492
<Route component={App}>
@@ -498,7 +498,7 @@ By default, the query parameters will just pass through but you can specify them
498498

499499
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`.
500500

501-
```jsx
501+
```js
502502
<Route path="course/:courseId">
503503
<Route path="dashboard" />
504504
{/* /course/123/home -> /course/123/dashboard */}
@@ -549,7 +549,7 @@ A subset of `this.props.params` that were directly specified in this component's
549549
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`.
550550

551551
##### Example
552-
```jsx
552+
```js
553553
render((
554554
<Router>
555555
<Route path="/" component={App}>
@@ -577,7 +577,7 @@ class App extends React.Component {
577577
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.
578578

579579
#### Example
580-
```jsx
580+
```js
581581
render((
582582
<Router>
583583
<Route path="/" component={App}>
@@ -649,7 +649,7 @@ and
649649
enhancers from `history`
650650

651651
#### Example
652-
```jsx
652+
```js
653653
import createHashHistory from 'history/lib/createHashHistory'
654654
const history = useRouterHistory(createHashHistory)({ queryKey: false })
655655
```

docs/Glossary.md

+20-20
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ This is a glossary of common terms used in the React Router codebase and documen
2727

2828
## Action
2929

30-
```jsx
30+
```js
3131
type Action = 'PUSH' | 'REPLACE' | 'POP';
3232
```
3333

@@ -39,15 +39,15 @@ An *action* describes the type of change to a URL. Possible values are:
3939

4040
## Component
4141

42-
```jsx
42+
```js
4343
type Component = ReactClass | string;
4444
```
4545

4646
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).
4747

4848
## EnterHook
4949

50-
```jsx
50+
```js
5151
type EnterHook = (nextState: RouterState, replace: RedirectFunction, callback?: Function) => any;
5252
```
5353

@@ -65,15 +65,15 @@ A *hash* is a string that represents the hash portion of the URL. It is synonymo
6565

6666
## LeaveHook
6767

68-
```jsx
68+
```js
6969
type LeaveHook = (prevState: RouterState) => any;
7070
```
7171

7272
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.
7373

7474
## Location
7575

76-
```jsx
76+
```js
7777
type Location = {
7878
pathname: Pathname;
7979
search: QueryString;
@@ -108,15 +108,15 @@ You can read more about location descriptors in [the `history` docs](https://git
108108

109109
## LocationKey
110110

111-
```jsx
111+
```js
112112
type LocationKey = string;
113113
```
114114

115115
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?".
116116

117117
## LocationState
118118

119-
```jsx
119+
```js
120120
type LocationState = ?Object;
121121
```
122122
@@ -129,55 +129,55 @@ This type gets its name from the first argument to HTML5's [`pushState`][pushSta
129129
130130
## Params
131131
132-
```jsx
132+
```js
133133
type Params = Object;
134134
```
135135
136136
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.
137137
138138
## Path
139139
140-
```jsx
140+
```js
141141
type Path = Pathname + QueryString + Hash;
142142
```
143143
144144
A *path* represents a URL path.
145145
146146
## Pathname
147147
148-
```jsx
148+
```js
149149
type Pathname = string;
150150
```
151151
152152
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.
153153

154154
## Query
155155

156-
```jsx
156+
```js
157157
type Query = Object;
158158
```
159159

160160
A *query* is the parsed version of a [query string](#querystring).
161161

162162
## QueryString
163163

164-
```jsx
164+
```js
165165
type QueryString = string;
166166
```
167167

168168
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.
169169

170170
## RedirectFunction
171171

172-
```jsx
172+
```js
173173
type RedirectFunction = (state: ?LocationState, pathname: Pathname | Path, query: ?Query) => void;
174174
```
175175

176176
A *redirect function* is used in [`onEnter` hooks](#enterhook) to trigger a transition to a new URL.
177177

178178
## Route
179179

180-
```jsx
180+
```js
181181
type Route = {
182182
component: RouteComponent;
183183
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
192192
193193
## RouteComponent
194194
195-
```jsx
195+
```js
196196
type RouteComponent = Component;
197197
```
198198
@@ -208,23 +208,23 @@ Route components should generally be component classes rather than strings. This
208208
209209
## RouteConfig
210210
211-
```jsx
211+
```js
212212
type RouteConfig = Array<Route>;
213213
```
214214
215215
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.
216216
217217
## RouteHook
218218
219-
```jsx
219+
```js
220220
type RouteHook = (nextLocation?: Location) => any;
221221
```
222222
223223
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 `return false` 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.
224224
225225
## RoutePattern
226226
227-
```jsx
227+
```js
228228
type RoutePattern = string;
229229
```
230230
@@ -239,7 +239,7 @@ Route patterns are relative to the pattern of the parent route unless they begin
239239
240240
## Router
241241
242-
```jsx
242+
```js
243243
type Router = {
244244
push(location: LocationDescriptor) => void;
245245
replace(location: LocationDescriptor) => void;
@@ -255,7 +255,7 @@ A *router* object allows for procedural manipulation of the routing state.
255255
256256
## RouterState
257257
258-
```jsx
258+
```js
259259
type RouterState = {
260260
location: Location;
261261
routes: Array<Route>;

docs/Introduction.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ To illustrate the problems React Router is going to solve for you, let's build a
66

77
### Without React Router
88

9-
```jsx
9+
```js
1010
import React from 'react'
1111
import { render } from 'react-dom'
1212

@@ -101,7 +101,7 @@ We'd have to make our URL parsing a lot smarter, and we would end up with a lot
101101

102102
Let's refactor our app to use React Router.
103103

104-
```jsx
104+
```js
105105
import React from 'react'
106106
import { render } from 'react-dom'
107107

@@ -148,7 +148,7 @@ React Router knows how to build nested UI for us, so we don't have to manually f
148148

149149
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:
150150

151-
```jsx
151+
```js
152152
const routes = {
153153
path: '/',
154154
component: App,
@@ -166,7 +166,7 @@ render(<Router history={history} routes={routes} />, document.body)
166166

167167
Alright, now we're ready to nest the inbox messages inside the inbox UI.
168168

169-
```jsx
169+
```js
170170
// Make a new component to render inside of Inbox
171171
const Message = React.createClass({
172172
render() {
@@ -228,7 +228,7 @@ And visits to `/inbox` will build this:
228228

229229
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`.
230230

231-
```jsx
231+
```js
232232
const Message = React.createClass({
233233

234234
componentDidMount() {

0 commit comments

Comments
 (0)