- BrowserRouter : 创建URL
<BrowserRouter />
http://example.com/about
- HashRouter: 创建URL
<BrowserRouter />
http://example.com/#/about
- Route : 路由显示什么组件,显示在什么位置,它有三个props用来定义渲染内容:
- component
- render
- children
- switch : The is not required for grouping s, but it can be quite useful. A will iterate over all of its children elements and only render the first one that matches the current location. This helps when multiple route’s paths match the same pathname, when animating transitions between routes, and in identifying when no routes match the current location (so that you can render a “404” component).=>{
- switch 将迭代所有route子元素,仅渲染与当前位置匹配的第一个子元素.
- 当没有路径与当前位置匹配的时候就选择没有设置path props 的组件进行渲染.(这样的功能可以实现404的效果) }
- Link : a 链接作用, to 属性不能少.
- NavLink : 一个特殊版本,它将在与当前URL匹配时为渲染元素添加样式属性。
- Redirect : 当
<Redirect>
被使用的时候,它会将当前url导入他的to值指向的url组件.
-
dome1 是关于基本的使用.
- exact 作用的让定义了这个props的组件仅在url等于path值的时候显示.
- match 在 this.props 中
-
dome2 是关于url参数的获取.
-
dome3 理解 switch
- switch 将迭代所有route子元素,仅渲染与当前位置匹配的第一个子元素.
- 当没有路径与当前位置匹配的时候就选择没有设置path props 的组件进行渲染.(这样的功能可以实现404的效果)
-
重定向
-
自定义路由