Skip to content

Commit 0625e76

Browse files
authored
Merge pull request #3673 from reactjs/syntax-jsx
Improve syntax highlighting in docs
2 parents 5538899 + d16ac7d commit 0625e76

21 files changed

+124
-124
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Using [npm](https://www.npmjs.com/):
3737

3838
Then with a module bundler like [webpack](https://webpack.github.io/) that supports either CommonJS or ES2015 modules, use as you would anything else:
3939

40-
```js
40+
```jsx
4141
// using an ES6 transpiler, like babel
4242
import { Router, Route, Link } from 'react-router'
4343

@@ -57,7 +57,7 @@ You can find the library on `window.ReactRouter`.
5757

5858
### What's it look like?
5959

60-
```js
60+
```jsx
6161
import React from 'react'
6262
import { render } from 'react-dom'
6363
import { Router, Route, Link, browserHistory } from 'react-router'

docs/API.md

Lines changed: 16 additions & 16 deletions
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-
```js
56+
```jsx
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-
```js
64+
```jsx
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-
```js
143+
```jsx
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
@@ -172,7 +172,7 @@ Contains data and methods relevant to routing. Most useful for imperatively tran
172172
##### `push(pathOrLoc)`
173173
Transitions to a new URL, adding a new entry in the browser history.
174174

175-
```js
175+
```jsx
176176
router.push('/users/12')
177177

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

245-
```js
245+
```jsx
246246
const routes = (
247247
<Route component={App}>
248248
<Route path="groups" component={Groups} />
@@ -265,7 +265,7 @@ class App extends React.Component {
265265
##### `components`
266266
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]`.
267267

268-
```js
268+
```jsx
269269
// Think of it outside the context of the router - if you had pluggable
270270
// portions of your `render`, you might do it like this:
271271
// <App main={<Users />} sidebar={<UsersSidebar />} />
@@ -316,7 +316,7 @@ Same as `component` but asynchronous, useful for code-splitting.
316316
###### `callback` signature
317317
`cb(err, component)`
318318

319-
```js
319+
```jsx
320320
<Route path="courses/:courseId" getComponent={(nextState, cb) => {
321321
// do asynchronous stuff to find the components
322322
cb(null, Course)
@@ -330,7 +330,7 @@ code-splitting.
330330
###### `callback` signature
331331
`cb(err, components)`
332332

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

351-
```js
351+
```jsx
352352
const userIsInATeam = (nextState, replace, callback) => {
353353
fetch(...)
354354
.then(response = response.json())
@@ -389,7 +389,7 @@ Same as `childRoutes` but asynchronous and receives `partialNextState`. Useful f
389389
###### `callback` signature
390390
`cb(err, routesArray)`
391391

392-
```js
392+
```jsx
393393
let myRoute = {
394394
path: 'course/:courseId',
395395
childRoutes: [
@@ -436,7 +436,7 @@ Same as `indexRoute`, but asynchronous and receives `partialNextState`. As with
436436
###### `callback` signature
437437
`cb(err, route)`
438438

439-
```js
439+
```jsx
440440
// For example:
441441
let myIndexRoute = {
442442
component: MyIndex
@@ -472,7 +472,7 @@ The path you want to redirect to.
472472
##### `query`
473473
By default, the query parameters will just pass through but you can specify them if you need to.
474474

475-
```js
475+
```jsx
476476
// Say we want to change from `/profile/123` to `/about/123`
477477
// and redirect `/get-in-touch` to `/contact`
478478
<Route component={App}>
@@ -484,7 +484,7 @@ By default, the query parameters will just pass through but you can specify them
484484

485485
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`.
486486

487-
```js
487+
```jsx
488488
<Route path="course/:courseId">
489489
<Route path="dashboard" />
490490
{/* /course/123/home -> /course/123/dashboard */}
@@ -535,7 +535,7 @@ A subset of `this.props.params` that were directly specified in this component's
535535
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`.
536536

537537
##### Example
538-
```js
538+
```jsx
539539
render((
540540
<Router>
541541
<Route path="/" component={App}>
@@ -563,7 +563,7 @@ class App extends React.Component {
563563
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.
564564

565565
#### Example
566-
```js
566+
```jsx
567567
render((
568568
<Router>
569569
<Route path="/" component={App}>
@@ -635,7 +635,7 @@ and
635635
enhancers from `history`
636636

637637
#### Example
638-
```js
638+
```jsx
639639
import createHashHistory from 'history/lib/createHashHistory'
640640
const history = useRouterHistory(createHashHistory)({ queryKey: false })
641641
```

docs/Glossary.md

Lines changed: 20 additions & 20 deletions
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-
```js
30+
```jsx
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-
```js
42+
```jsx
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-
```js
50+
```jsx
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-
```js
68+
```jsx
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-
```js
76+
```jsx
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-
```js
111+
```jsx
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-
```js
119+
```jsx
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-
```js
132+
```jsx
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-
```js
140+
```jsx
141141
type Path = Pathname + QueryString + Hash;
142142
```
143143
144144
A *path* represents a URL path.
145145
146146
## Pathname
147147
148-
```js
148+
```jsx
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-
```js
156+
```jsx
157157
type Query = Object;
158158
```
159159

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

162162
## QueryString
163163

164-
```js
164+
```jsx
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-
```js
172+
```jsx
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-
```js
180+
```jsx
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-
```js
195+
```jsx
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-
```js
211+
```jsx
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-
```js
219+
```jsx
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-
```js
227+
```jsx
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-
```js
242+
```jsx
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-
```js
258+
```jsx
259259
type RouterState = {
260260
location: Location;
261261
routes: Array<Route>;

docs/Introduction.md

Lines changed: 5 additions & 5 deletions
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-
```js
9+
```jsx
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-
```js
104+
```jsx
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-
```js
151+
```jsx
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-
```js
169+
```jsx
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-
```js
231+
```jsx
232232
const Message = React.createClass({
233233

234234
componentDidMount() {

0 commit comments

Comments
 (0)