当前位置:网站首页>Nested (multi-level) childrn routes, query parameters, named routes, replace attribute, props configuration of routes, params parameters of routes
Nested (multi-level) childrn routes, query parameters, named routes, replace attribute, props configuration of routes, params parameters of routes
2022-07-07 09:23:00 【Brave * Niuniu】
Even once , I want to run on this planet .
Configure routing rules , Use children Configuration item :
routes:[
{
path:'/about',
component:About,
},
{
path:'/home',
component:Home,
children:[ // adopt children Configure child routing
{
path:'news', // Don't write here :/news
component:News
},
{
path:'message',// Don't write here :/message
component:Message
}
]
}
]
1. Jump ( To write the full path ):
<router-link to="/home/news">News</router-link>
query Parameters
Route nesting :
// Create a router
const router = new VueRouter({
routes: [
{
path: '/about',
component: About
},
{
path: '/home',
component: Home,
children: [
{
path: 'home-news',
component: News
},
{
path: 'home-message',
component: Message,
children: [
{
path: 'detail',
component: Detail
}
]
}
]
},
]
})
Jump route and carry query Parameters ,to String writing
<ul>
<li v-for="m in messageList" :key="m.id">
<!-- Jump route and carry query Parameters ,to String writing -->
<router-link :to="`/home/home-message/detail?id=${m.id}&title=${m.title}`">{
{
m.title}}</router-link>
</li>
</ul>
Jump route and carry query Parameters ,to The object of writing
<!-- Jump route and carry query Parameters ,to The object of writing -->
<router-link :to="{
path:'/home/home-message/detail',
query:{
id:m.id,
title:m.title
}
}">
{
{
m.title}}
</router-link>
Get the passed information according to the component
<ul>
<li> Message number {
{
$route.query.id}}</li>
<li> Message title {
{
$route.query.title}}</li>
</ul>
Named route
effect : It can simplify the jump of routing .
How to use
- Name the route :
{
path:'/demo',
component:Demo,
children:[
{
path:'test',
component:Test,
children:[
{
name:'hello' // Name the route
path:'welcome',
component:Hello,
}
]
}
]
}
Simplify jump :
<!-- Before simplification , You need to write the full path -->
<router-link to="/demo/test/welcome"> Jump </router-link>
<!-- simplified , Jump directly by name -->
<router-link :to="{name:'hello'}"> Jump </router-link>
<!-- Simplify the writing method and transfer parameters -->
<router-link
:to="{
name:'hello',
query:{
id:666,
title:' Hello '
}
}"
> Jump </router-link>
6. The routing params Parameters
Configure the routing , To declare acceptance params Parameters
{ path:'/home', component:Home, children:[ { path:'news', component:News }, { component:Message, children:[ { name:'xiangqing', path:'detail/:id/:title', // Use placeholder declarations to receive params Parameters component:Detail } ] } ] }Pass parameters
<!-- Jump and carry params Parameters ,to String writing -->
<router-link :to="/home/message/detail/666/ Hello "> Jump </router-link>
<!-- Jump and carry params Parameters ,to The object of writing -->
<router-link :to="{ name:'xiangqing', params:{ id:666, title:' Hello ' } }" > Jump </router-link>
Particular attention : Routing carries params When parameters are , If you use to The object of writing , Cannot be used path Configuration item , You have to use name To configure !
- Receiving parameters :
$route.params.id
$route.params.title
7. The routing props To configure
effect : Make it easier for routing components to receive parameters
{
name:'xiangqing',
path:'detail/:id',
component:Detail,
// The first way to write it :props Value as object , All... In this object key-value All combinations will eventually pass props Pass to Detail Components
// props:{a:900}
// The second way :props The value is Boolean , The Boolean value is true, Then route all received params Parameters through props Pass to Detail Components
// props:true
// The third way :props The value is a function , Each set of objects returned by this function key-value Will pass props Pass to Detail Components
props($route){
return {
id:$route.query.id,
title:$route.query.title
}
}
}
8.<router-link> Of replace attribute
- effect : Controls the mode of operating browser history when routing jumps
- Browser history can be written in two ways : Respectively
pushandreplace,pushIs to add history ,replaceIs to replace the current record . The default value for route jump ispush - How to open
replacePattern :<router-link replace .......>News</router-link>
边栏推荐
- Selenium mouse sliding operation event
- DRF defines views and routes
- What is the use of PMP certificate?
- Jemter operation
- Port multiplexing and re imaging
- Data association between two interfaces of postman
- Add new item after the outbound delivery order of SAP mm sto document is created?
- Zen - batch import test cases
- sqlplus乱码问题,求解答
- Schema-validation: wrong column type encountered in column XXX in table XXX
猜你喜欢

Postman interface test (I. installation and use)

Cesium load vector data

二叉树高频题型

正则匹配以XXX开头的,XXX结束的

Interview question: general layout and wiring principles of high-speed PCB

十二、排序

External interrupt to realize key experiment

The configuration and options of save actions are explained in detail, and you won't be confused after reading it

【云原生】DevOps(一):DevOps介绍及Code工具使用

Data association between two interfaces of postman
随机推荐
JVM 垃圾回收 详细学习笔记(二)
PMP Exam Preparation experience, seek common ground while reserving differences, and successfully pass the exam
What are the suggestions for PMP candidates?
Add new item after the outbound delivery order of SAP mm sto document is created?
C语言指针(中篇)
Jemter operation
DRF authentication, permissions, and flow restrictions (only for views in DRF)
Mysql database index study notes
Full link voltage test of the e-commerce campaign Guide
SiteMesh getting started example
The use of recycling ideas
Cesium does not support 4490 problem solution and cesium modified source code packaging scheme
Regularly modify the system time of the computer
Locust performance test 3 (high concurrency, parameter correlation, assembly point)
LeetCode每日一题(2316. Count Unreachable Pairs of Nodes in an Undirected Graph)
Two schemes of unit test
(3/8)枚举的不当用法 之 方法参数(二)
二叉树高频题型
Serializer & modelserializer of DRF serialization and deserialization
Zen - batch import test cases