当前位置:网站首页>Route (II)
Route (II)
2022-07-02 14:02:00 【Deduct 1 to send hell fire】
One . Routing jump replace Method
1. effect : Controls the mode of operating browser history when routing jumps
Browser history can be written in two ways :push and replace, among push Is to add history ,replace Is to replace the current record . The default value for route jump is push The way
2. Turn on replace Pattern :
<router-link replace ...>News</router-link>
Two . Programming route navigation
effect : Don't use
<router-link>
Implement route jump , Make routing jump more flexibleSpecific code
this.$router.push({ name:'xiangqing', params:{ id:xxx, title:xxx } }) this.$router.replace({ name:'xiangqing', params:{ id:xxx, title:xxx } }) this.$router.forward() // Forward this.$router.back() // back off this.$router.go() // You can move forward or backward
3、 ... and . Cache routing components
effect : Keep the routing components not shown mounted , Not destroyed
// Cache a routing component
<keep-alive include="News"> //include Write the name of the component you want to cache , Not writing means all caches
<router-view></router-view>
</keep-alive>
// Cache multiple routing components
<keep-alive :include="['News','Message']">
<router-view></router-view>
</keep-alive>
Four . Two life cycle hooks
activated
anddeactivated
Are two hooks unique to the routing component , Used to capture the activation status of routing components- Specific use :
activated
Triggered when the routing component is activateddeactivated
Triggered when the routing component is deactivated
activated(){
console.log('News The component is activated ')
this.timer = setInterval(() => {
this.opacity -= 0.01
if(this.opacity <= 0) this.opacity = 1
},16)
},
deactivated(){
console.log('News The component is deactivated ')
clearInterval(this.timer)
}
5、 ... and . Route guard
5.1 Global guard
// Global front route guard ———— When initializing 、 Called before each route switch
router.beforeEach((to,from,next) => {
console.log(' Front routing guard ',to,from)
if(to.meta.isAuth){
if(localStorage.getItem('school')==='atguigu'){
next()
}else{
alert(' The school name is wrong , No permission to view !')
}
}else{
next()
}
})
// Global post route guard ———— It is called during initialization 、 Called after each route switch
router.afterEach((to,from)=>{
console.log(' Post routing guard ',to,from)
document.title = to.meta.title || ' Silicon Valley system '
})
5.2 Exclusive routing guard
{
name:'zhuye',
path:'/home',
component:Home,
meta:{title:' Home page '},
children:[
{
name:'xinwen',
path:'news',
component:News,
meta:{title:' Journalism '},
// Exclusive guard , Called after a specific route switch
beforeEnter(to,from,next){
console.log(' Exclusive routing guard ',to,from)
if(localStorage.getItem('school') === 'atguigu'){
next()
}else{
alert(' No permission to view ')
}
}
}
5.3 Routing guard inside the component
src/pages/About.vue
:
<template>
<h2> I am a About Content of the component </h2>
</template>
<script>
export default {
name:'About',
// Through routing rules , Called when leaving the component
beforeRouteEnter (to, from, next) {
console.log('About--beforeRouteEnter',to,from)
if(localStorage.getItem('school')==='atguigu'){
next()
}else{
alert(' The school name is wrong , No permission to view !')
}
},
// Through routing rules , Called when leaving the component
beforeRouteLeave (to, from, next) {
console.log('About--beforeRouteLeave',to,from)
next()
}
}
</script>
6、 ... and 、 Two working modes of router
For one url Come on , What is? hash value ?—— # And what follows is hash value
hash Values will not be included in HTTP In request , namely :hash The value will not be brought to the server
hash Pattern :
The address always carries # Number , Not beautiful
If you send the address through a third-party mobile phone in the future app Share , if app The verification is strict , The address will be marked as illegal
Good compatibility
history Pattern :
The address is clean , beautiful
Compatibility and hash Slightly worse than the model
Back end personnel support is required when the application is deployed online , Solve the problem of refreshing the page server 404 The problem of
connect-history-api-fallback
nginx
边栏推荐
- Which do you choose between Alibaba P7 with an annual salary of 900000 and deputy department level cadres?
- Development skills of rxjs observable custom operator
- 无主灯设计:如何让智能照明更加「智能」?
- 默认插槽,具名插槽,作用域插槽
- [usaco05jan]watchcow s (Euler loop)
- P1042 [NOIP2003 普及组] 乒乓球
- (POJ - 1984) navigation nightare (weighted and search set)
- 【文档树、设置】字体变小
- Getting started with QT - making a simple calculator
- Halcon extract orange (Orange)
猜你喜欢
[技术发展-22]:网络与通信技术的应用与发展快速概览-2- 通信技术
Node. JS accessing PostgreSQL database through ODBC
Qt新项目_MyNotepad++
Code implementation MNLM
Penetrate the remote connection database through the Intranet
Codeforces Round #803 (Div. 2)(A~D)
题解:《你的飞碟在这儿》、《哥德巴赫猜想》
OpenFOAM:lduMatrix&lduAddressing
混沌工程平台 ChaosBlade-Box 新版重磅发布
Integral link, inertia link and proportion link in Simulink
随机推荐
Whole house Wi Fi: a pain point that no one can solve?
Launcher启动过程
量子三体问题: Landau Fall
Unity small map production [2]
kaggle如何使用utility script
rxjs Observable 自定义 Operator 的开发技巧
When tidb meets Flink: tidb efficiently enters the lake "new play" | tilaker team interview
P3807 [template] Lucas theorem /lucas theorem
Pattern matching and regular expressions in PostgreSQL - Das
Browser driven Download
Development skills of rxjs observable custom operator
Qt原代码基本知识
The 29 year old programmer in Shanghai was sentenced to 10 months for "deleting the database and running away" on the day of his resignation!
Error: eacces: permission denied, access to "/usr/lib/node_modules"
c# 水晶报表打印
Android kotlin broadcast technology point
刚好1000粉丝,记录一下
当贝投影4K激光投影X3 Pro获得一致好评:万元投影仪首选
PyQt5_QScrollArea内容保存成图片
The xftp connection Haikang camera reported an error: the SFTP subsystem application has been rejected. Please ensure that the SFTP subsystem settings of the SSH connection are valid