当前位置:网站首页>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
边栏推荐
- MySQL45讲——学习极客时间MySQL实战45讲笔记—— 04 | 深入浅出索引(上)
- ArrayList and LinkedList
- MySQL45讲——学习极客时间MySQL实战45讲笔记—— 05 | 深入浅出索引(下)
- (POJ - 1984) navigation nightare (weighted and search set)
- Astro learning notes
- Three talking about exception -- error handling
- Gee learning notes 2
- selenium 在pycharm中安装selenium
- P1908 reverse sequence pair
- 故事点 vs. 人天
猜你喜欢

千元投影小明Q1 Pro和极米NEW Play谁更好?和哈趣K1比哪款配置更高?

SystemServer进程

Runhe hi3516 development board openharmony small system and standard system burning

Find love for speed in F1 delta time Grand Prix

Chaos engineering platform chaosblade box new heavy release

QT new project_ MyNotepad++

刚好1000粉丝,记录一下

When tidb meets Flink: tidb efficiently enters the lake "new play" | tilaker team interview

Daily practice of C language --- monkeys divide peaches

OpenFOAM:lduMatrix&lduAddressing
随机推荐
How to explain binary search to my sister? This is really difficult, fan!
Browser driven Download
Solution: Compression Technology (original version and sequel version)
P1347 sorting (topology + SPFA judgment ring or topology [inner judgment ring])
OpenFOAM:lduMatrix&lduAddressing
使用BLoC 构建 Flutter的页面实例
Memory management 01 - link script
Whole house Wi Fi: a pain point that no one can solve?
693. 行程排序(map + 拓扑)
路由(二)
MySQL 45 lecture - learning from the actual battle of geek time MySQL 45 Lecture Notes - 04 | easy to understand index (Part 1)
Achievements in science and Technology (27)
量子三体问题: Landau Fall
故事點 vs. 人天
[USACO05JAN]Watchcow S(欧拉回路)
Systemserver process
Codeforces Round #803 (Div. 2)(A~D)
rxjs Observable 自定义 Operator 的开发技巧
On flow delivery between microservices
Selenium installing selenium in pycharm