当前位置:网站首页>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>
边栏推荐
- How to use Arthas to view class variable values
- Postman interface test (II. Set global variables \ sets)
- PMP examination experience sharing
- NVIC中断优先级管理
- C language pointer (Part 1)
- Locust performance test 4 (custom load Policy)
- STM32的时钟系统
- Unittest simple project
- Leetcode question brushing record (array) combination sum, combination sum II
- JVM garbage collection detailed learning notes (II)
猜你喜欢
Mysql database transaction learning notes
Locust performance test 2 (interface request)
Postman interface test (I. installation and use)
NVIC中断优先级管理
Sublime Text4 download the view in bower and set the shortcut key
Locust performance test 3 (high concurrency, parameter correlation, assembly point)
C language pointer (Part 2)
stm32和电机开发(从单机版到网络化)
Pytest installation (command line installation)
JVM garbage collection detailed learning notes (II)
随机推荐
Using JWT to realize login function
Kubernetes cluster capacity expansion to add node nodes
Pytest+request+allure+excel interface automatic construction from 0 to 1 [five nails / flying Book notice]
Locust performance test 2 (interface request)
Add new item after the outbound delivery order of SAP mm sto document is created?
Huawei HCIP - datacom - Core 03 jours
Integer or int? How to select data types for entity classes in ORM
Implementation of corner badge of Youmeng message push
【Istio Network CRD VirtualService、Envoyfilter】
5A summary: seven stages of PMP learning
NVIC interrupt priority management
stm32和电机开发(从单机版到网络化)
Variable parameter of variable length function
Postman data driven
十二、排序
Jenkins+ant+jmeter use
四、机器学习基础
Some pit avoidance guidelines for using Huawei ECS
Common short chain design methods
LeetCode每日一题(2316. Count Unreachable Pairs of Nodes in an Undirected Graph)