当前位置:网站首页>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
activatedanddeactivatedAre two hooks unique to the routing component , Used to capture the activation status of routing components- Specific use :
activatedTriggered when the routing component is activateddeactivatedTriggered 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
边栏推荐
- Qt-制作一个简单的计算器-实现四则运算
- Design of non main lamp: how to make intelligent lighting more "intelligent"?
- Systemserver process
- When tidb meets Flink: tidb efficiently enters the lake "new play" | tilaker team interview
- Dingtalk 发送消息
- P3807 [template] Lucas theorem /lucas theorem
- Drawing Nyquist diagram with MATLAB
- MySQL45讲——学习极客时间MySQL实战45讲笔记—— 04 | 深入浅出索引(上)
- D language, possible 'string plug-ins'
- Qt新项目_MyNotepad++
猜你喜欢

selenium 元素定位方法

Pointer from entry to advanced (1)

MySQL45讲——学习极客时间MySQL实战45讲笔记—— 04 | 深入浅出索引(上)
![[deep learning] simple implementation of neural network forward propagation](/img/a6/9b4896c62e9b77f9d528c3c9efc58f.jpg)
[deep learning] simple implementation of neural network forward propagation

Origin绘制热重TG和微分热重DTG曲线

题解《子数整数》、《欢乐地跳》、《开灯》

万物生长大会在杭召开,当贝入选2022中国未来独角兽TOP100榜单

QT - make a simple calculator - realize four operations

Drawing Nyquist diagram with MATLAB

Design of non main lamp: how to make intelligent lighting more "intelligent"?
随机推荐
SystemServer进程
Selenium installing selenium in pycharm
Astro learning notes
ensp简单入门
代码实现MNLM
Qt原代码基本知识
Explanation: here is your UFO, Goldbach conjecture
[technology development-22]: rapid overview of the application and development of network and communication technology-2-communication Technology
Codeforces Round #803 (Div. 2)(A~D)
(POJ - 1308)Is It A Tree? (tree)
In 2021, the global revenue of structural bolts was about $796.4 million, and it is expected to reach $1097.6 million in 2028
Add sequence number column to query results in MySQL
[Blue Bridge Cup] children's worship circle
Word frequency statistics & sorting
故事点 vs. 人天
题解:《压缩技术》(原版、续集版)
rxjs Observable 自定义 Operator 的开发技巧
How to explain binary search to my sister? This is really difficult, fan!
Browser driven Download
石子合并板子【区间DP】(普通石子合并 & 环形石子合并)