<router-link>
Must it<router-view>
be used together?
Yes, <router-link> 组件必须配合 <router-view>
use it, even if you use it, <router-link>
you must use it <router-view>
.
<router-link>
The component is used to create a navigation link. When the user clicks on the link, it will switch to the component corresponding to the path of the to attribute and display it in <router-view>
. <router-view>
The component is used to display the component content corresponding to the current route.
- Does that
<router-view>
have to<router-link>
be used together?
<router-view>
The components do not need to be used together <router-link>
, even if they are used, <router-view>
they can not be used <router-link>
.
<router-view>
The function of the component is to 路由的路径
render the corresponding component content according to the current (it should be noted that the routing path can be provided by the router-link or the navigation path of the browser).
<router-view>
Two ways to use :
- When the user clicks on
<router-link>
the link of the component, the routing will change, and the corresponding component will be loaded to<router-view>
display in according to the new routing path. - You can just use
<router-view>
the component to display component content without using<router-link>
. For example, in a static page without navigation links, you can just use<router-view>
to render当前路由对应的组件
without using<router-link>
to generate links.