当前位置:网站首页>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
push
andreplace
,push
Is to add history ,replace
Is to replace the current record . The default value for route jump ispush
- How to open
replace
Pattern :<router-link replace .......>News</router-link>
边栏推荐
- Locust performance test 2 (interface request)
- Pytest+request+allure+excel interface automatic construction from 0 to 1 [five nails / flying Book notice]
- Serializer & modelserializer of DRF serialization and deserialization
- 2020 year end summary
- Chaosblade: introduction to chaos Engineering (I)
- Why is access to the external network prohibited for internal services of the company?
- External interrupt to realize key experiment
- sqlplus乱码问题,求解答
- 信息安全实验二 :使用X-SCANNER扫描工具
- Mysql数据库-锁-学习笔记
猜你喜欢
PMP Exam Preparation experience systematically improve project management knowledge through learning
正则匹配以XXX开头的,XXX结束的
sqlplus乱码问题,求解答
Summary of PMP learning materials
Zen - batch import test cases
数据在内存中的存储
Detailed learning notes of JVM memory structure (I)
Network request process
Pycharm create a new file and add author information
The essence of high availability
随机推荐
What are the suggestions for PMP candidates?
数据在内存中的存储
Cesium does not support 4490 problem solution and cesium modified source code packaging scheme
Common short chain design methods
C language pointer (exercises)
5A summary: seven stages of PMP learning
H3C vxlan configuration
(3/8)枚举的不当用法 之 方法参数(二)
What is MD5
Network request process
Upgrade Alibaba cloud RDS (relational database service) instance to com mysql. jdbc. exceptions. Troubleshooting of jdbc4.communicationsexception
Interface test API case, data and interface separation
超十万字_超详细SSM整合实践_手动实现权限管理
PMP examination experience sharing
Storage of data in memory
Cesium load vector data
How to pass the PMP Exam in a short time?
Systick滴答定时器
DRF authentication, permissions, and flow restrictions (only for views in DRF)
徽商期货公司评级是多少?开户安全吗?我想开户,可以吗?