I have finished dynamic routing, nested routing, etc., here are finished with named routing and named view, the basic usage of vue-router is over.
vue-router named route
① named route is a route name when routers configured to route different definition of the name, this advantage is that you can use in router-link
the to
transmission properties of an object when jumping routes in order to achieve the router.push
same effect:
<router-link :to="{ name: 'user', params: { userId: 123 }}">User</router-link>
Equivalent to
router.push({ name: 'user', params: { userId: 123 }})
②First of all, name the goods route in router文件夹下
" index.js
(It has been named before).
Then go to the test.vue
page and type:
Finally go to the browser to see the effect
Click on the last line to jump
Named view
To put it simply, router-view
define different names for different , and render the corresponding components through the names.
example
①router》》index.js routing page, delete all the previous writing and change it to the following:
②Then enter the page where the root route'/' is located, that is app.vue
, the first one router-view
will use the default without naming, and the other two will router-view
add name
attribute naming.
④Finally we can see the effect.
------------------------------------------------------------------------------------------------------------
Summary of learning vue-router:
The top-level vue sets the default interface, and the default router-view route is displayed.
index.js sets the index router path.
The branch layer vue displays the content of the index jump.
Home→Index→Content