1
+ ## Redirect
2
+
1
3
A ` Redirect ` sets up a redirect to another route in your application to
2
4
maintain old URLs.
3
5
4
- Props
5
- -----
6
+ ### Props
6
7
7
- ### ` from `
8
+ #### ` from `
8
9
9
10
The path you want to redirect from, including dynamic segments.
10
11
11
- ### ` to `
12
-
13
- The route path you want to redirect to.
14
-
15
- ### ` params `
12
+ #### ` to `
16
13
17
- By default, the parameters will just pass through to the new route, but
18
- you can specify them if you need to (usually you shouldn't).
14
+ The path you want to redirect to.
19
15
20
- ### ` query `
16
+ #### ` query `
21
17
22
- By default, the query parameters will just pass through to the new
23
- route, but you can specify them if you need to (usually you shouldn't) .
18
+ By default, the query parameters will just pass through but you can
19
+ specify them if you need to.
24
20
25
- Example
26
- -------
21
+ ### Example
27
22
28
23
``` js
29
24
// lets say we want to change from `/profile/123` to `/about/123`
30
25
// and redirect `/get-in-touch` to `/contact`
31
26
< Route component= {App}>
32
- < Route path= " contact" component= {Contact}/ >
33
27
< Route path= " about/:userId" component= {UserProfile}/ >
34
- < Route path= " course/:courseId" >
35
- < Route path= " dashboard" component= {Dashboard}/ >
36
- < Route path= " assignments" component= {Assignments}/ >
37
- < / Route>
38
-
39
- {/* `/get-in-touch` -> `/contact` */ }
40
- < Redirect from= " /get-in-touch" to= " /contact" / >
41
28
42
29
{/* `/profile/123` -> `/about/123` */ }
43
30
< Redirect from= " /profile/:userId" to= " /about/:userId" / >
44
-
45
- {/* `/profile/me` -> `/about/123` */ }
46
- < Redirect from= " /profile/me" to= " /about/:userId" params= {{userId: SESSION .USER_ID }}/ >
47
31
< / Route>
48
32
```
49
33
50
34
Note that the ` <Redirect/> ` can be placed anywhere in the route
51
35
hierarchy, if you'd prefer the redirects to be next to their respective
52
36
routes, the ` from ` path will match the same as a regular route ` path ` .
53
- Currently, the ` to ` property of ` <Redirect/> ` needs to be an absolute path.
37
+ Currently, the ` to ` property of ` <Redirect/> ` needs to be an absolute
38
+ path. Pull requests welcome to make them handle relative paths too!
54
39
55
40
``` js
56
41
< Route path= " course/:courseId" >
@@ -59,3 +44,4 @@ Currently, the `to` property of `<Redirect/>` needs to be an absolute path.
59
44
< Redirect from= " home" to= " /course/:courseId/dashboard" / >
60
45
< / Route>
61
46
```
47
+
0 commit comments