当前位置:网站首页>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
边栏推荐
- kaggle如何使用utility script
- 基于ssm+jsp框架实现的学生选课信息管理系统【源码+数据库】
- Memory management 01 - link script
- rxjs Observable 自定义 Operator 的开发技巧
- Daily practice of C language --- monkeys divide peaches
- ensp简单入门
- Whole house Wi Fi: a pain point that no one can solve?
- MySQL 45 lecture - learning the actual battle of MySQL in Geek time 45 Lecture Notes - 05 | easy to understand index (Part 2)
- [document tree, setting] font becomes smaller
- When tidb meets Flink: tidb efficiently enters the lake "new play" | tilaker team interview
猜你喜欢
Integral link, inertia link and proportion link in Simulink
Explanation: here is your UFO, Goldbach conjecture
qt中uic的使用
Error: eacces: permission denied, access to "/usr/lib/node_modules"
Code implementation MNLM
[deep learning] simple implementation of neural network forward propagation
A better database client management tool than Navicat
Getting started with QT - making a simple calculator
I did it with two lines of code. As a result, my sister had a more ingenious way
How to explain binary search to my sister? This is really difficult, fan!
随机推荐
Sum of the first n terms of Fibonacci (fast power of matrix)
uniapp小程序 subPackages分包配置
Simple introduction to ENSP
How to set QT manual layout
Design of non main lamp: how to make intelligent lighting more "intelligent"?
混沌工程平台 ChaosBlade-Box 新版重磅发布
Skillfully use SSH to get through the Internet restrictions
【虹科技术分享】如何测试 DNS 服务器:DNS 性能和响应时间测试
Memory management 01 - link script
Characteristics of selenium
[USACO05JAN]Watchcow S(欧拉回路)
Development skills of rxjs observable custom operator
QT how to set fixed size
Will your sleep service dream of the extra bookinfo on the service network
大家信夫一站式信用平台让信用场景“用起来
Drawing Nyquist diagram with MATLAB
Qt入门-制作一个简易的计算器
Why is the default of switch followed by break?
Story point vs. Human Sky
错误:EACCES:权限被拒绝,访问“/usr/lib/node_modules”