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: docs/Glossary.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -132,7 +132,7 @@ A *route pattern* (or "path") is a string that describes a portion of a URL. Pat
132
132
133
133
-`:paramName` – matches a URL segment up to the next `/`, `?`, or `#`. The matched string is called a [param](#params)
134
134
-`()` – Wraps a portion of the URL that is optional
135
-
-`*` – Matches all characters (non-greedy) up to the next character in the pattern, or to the end of the URL if there is none, and creates a `splat` param
135
+
-`*` – Matches all characters (non-greedy) up to the next character in the pattern, or to the end of the URL if there is none, and creates a `splat`[param](#params)
136
136
137
137
Route patterns are relative to the pattern of the parent route unless they begin with a `/`, in which case they begin matching at the beginning of the URL.
Copy file name to clipboardExpand all lines: docs/RouteConfiguration.md
+35-2Lines changed: 35 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
## Route Configuration
2
2
3
-
Let's start with the simple app from [the introduction](Introduction.md).
3
+
A [route configuration](Glossary.md#routeconfig) is basically a set of instructions that tell a router how to try and [match the URL](RouteMatching.md) and what code to run when it does. To illustrate some of the features available in your route config, let's expand on the simple app from [the introduction](Introduction.md).
4
4
5
5
```js
6
6
importReactfrom'react';
@@ -67,7 +67,7 @@ URL | Components
67
67
68
68
### Adding an Index
69
69
70
-
Imagine we'd like to render another component inside of `App` when the URL is `/`. Currently, `this.props.children` is `undefined` in this case. We can use an `<IndexRoute>`for that.
70
+
Imagine we'd like to render another component inside of `App` when the URL is `/`. Currently, `this.props.children` is `undefined` in this case. We can use an `<IndexRoute>`to specify a "default" page.
71
71
72
72
```js
73
73
import { IndexRoute } from'react-router';
@@ -133,6 +133,8 @@ URL | Components
133
133
134
134
The ability to use absolute paths in deeply nested routes gives us complete control over what the URL looks like! We don't have to add more segments to the URL just to get nested UI.
135
135
136
+
**Note**: Absolute paths may not be used in route config that is [dynamically loaded](DynamicLoading.md).
137
+
136
138
### Preserving URLs
137
139
138
140
But wait just a minute ... we just changed a URL! [That's not cool](http://www.w3.org/Provider/Style/URI.html). Now everyone who had a link to `/inbox/messages/5` has a **broken link**. :(
@@ -159,3 +161,34 @@ React.render((
159
161
```
160
162
161
163
Now when someone clicks on that link to `/inbox/messages/5` they'll automatically be redirected to `/messages/5`. We don't hate our users anymore! :highfive:
164
+
165
+
### Alternate Configuration
166
+
167
+
Since [route](Glossary.md#route)s are usually nested, it's useful to use a concise nested syntax like [JSX](https://facebook.github.io/jsx/) to describe their relationship to one another. However, you may use an array of [route](Glossary.md#route) objects if you prefer to avoid using JSX.
168
+
169
+
The route config we've discussed up to this point could also be specified like this:
A [route](Glossary.md#route) has two attributes that determine whether or not it "matches" the URL: 1) [nesting](#nesting) and 2) its [`path`](#pathsyntax).
4
+
5
+
### Nesting
6
+
7
+
React Router uses the concept of nested routes to let you declare nested sets of views that should be rendered when a given URL is invoked. Nested routes are arranged in a tree-like structure. To find a match, React Router traverses the [route config](Glossary.md#routeconfig) depth-first searching for a route that matches the URL.
8
+
9
+
### Path Syntax
10
+
11
+
A route path is [a string pattern](Glossary.md#routepattern) that is used to match a URL (or a portion of one). Route paths are interpreted literally, except for the following special symbols:
12
+
13
+
-`:paramName` – matches a URL segment up to the next `/`, `?`, or `#`. The matched string is called a [param](Glossary.md#params)
14
+
-`()` – Wraps a portion of the URL that is optional
15
+
-`*` – Matches all characters (non-greedy) up to the next character in the pattern, or to the end of the URL if there is none, and creates a `splat`[param](Glossary.md#params)
16
+
17
+
```
18
+
<Route path="/hello/:name"> // matches /hello/michael and /hello/ryan
19
+
<Route path="/hello(/:name)"> // matches /hello, /hello/michael, and /hello/ryan
20
+
<Route path="/files/*.*"> // matches /files/hello.jpg and /files/path/to/hello.jpg
21
+
```
22
+
23
+
If a route uses a relative `path`, it builds upon the accumulated `path` of its ancestors. Nested routes may opt-out of this behavior by [using an absolute `path`](RouteConfiguration.md#decoupling-the-ui-from-the-url).
0 commit comments