Redirect

用于控制对旧路由的重定向,用于控制项目中的废弃路由。

该组件支持参数:

  1. // 下面的路由可以从 /profile/123 跳转到 /about/123
  2. <Route path="/" component={App}>
  3. <Route path="about/:userId" component={UserProfile} />
  4. <Redirect from="profile/:userId" to="about/:userId" />
  5. </Route>

同时也支持相对路由:

  1. // 可以从 /course/123/home 跳转到 /course/123/dashboard
  2. <Route path="course/:courseId">
  3. <Route path="dashboard" />
  4. <Redirect from="home" to="dashboard" />
  5. </Route>

属性

from { String }

想要重定向的旧路由

to { String }

需要重定向到的新路由