当前位置:网站首页>404 pages and routing hooks
404 pages and routing hooks
2022-07-26 13:40:00 【starriesWEB】
Routing mode
Two routing modes
hash: Path belt#, Such ashttp://localhost:8080/#/mainhistory: The path does not take#, Such ashttp://localhost:8080/main
Modify routing configuration
export default new Router({
mode: 'history',
routes: [
]
})
404 page
NotFound.vue
<template>
<h1>404, Your page is lost ...</h1>
</template>
<script> export default {
name: "NotFound" } </script>
<style scoped> </style>
Routing configuration
// Import components
import NotFound from '../views/NotFound'
// Add path at the end *
{
path: '*',
component: NotFound
}
As long as it does not conform to the previous routing configuration path , Jump to NotFound Components ,404 page
Routing hook
beforeRouteEnter Before entering the route beforeRouteLeave Execute before leaving the route
<script>
export default {
// stay props Set the parameters of the route in
props: ['id'],
name: "UserProfile",
beforeRouteEnter(to,from,next)=>{
// Can't get component instance this Because before the guards execute , The component instance has not been created yet
console.log(" Before entering the route ");
next();
},
beforeRouteLeave(to, from, next) {
// Called when leaving the corresponding route of the component You can access the component instance this
console.log(" Before leaving the route ");
}
}
</script>
Parameters
to: The goal to enter ( Routing objects )from: The route that the current navigation is about to leavenext: Routing control parameters , Be sure to call this methodnext(): Go to the next hook , If all hooks are executed , Go to the pagenext(false): Return to previous between pagesnext('newpath')perhapsnext({ path: 'newpath' }): Change the jump release of the route , Jump tonewpathroutenext((vm)=>{}): Only inbeforeRouteEnterHook use ,vmIs a component instance
beforeRouteEnter Get data before entering the route
# install axios vue-axios rely on
npm install --save axios vue-axios
index.js Add dependencies and install axios
import axios from 'axios'
import VueAxios from 'vue-axios'
Vue.use(VueAxios, axios);
static I'm gonna go ahead and create a new folder mock, establish json data data.json
{
"name": " Baidu ",
"url": "http://baidu.com",
"page": 1,
"isNonProfit": true,
"address": {
"street": " Han guangmen ",
"city": " Xi'an, Shaanxi ",
"country": " China "
},
"links": [
{
"name": "B standing ",
"url": "https://www.bilibili.com/"
},
{
"name": 4399,
"url": "https://www.4399.com/"
},
{
"name": " Baidu ",
"url": "https://www.baidu.com/"
}
]
}
Profile.vue Add method in
export default {
// stay props Set the parameters of the route in
props: ['id'],
name: "UserProfile",
beforeRouteEnter: (to,from,next)=>{
// Can't get component instance this Because before the guards execute , The component instance has not been created yet
next(vm => {
// Before entering the route , call vm Example of getData Method to get data
vm.getData();
});
console.log(" Before entering the route ");
next();
}
}
methods: {
// Use axios get data
getData: function () {
this.axios({
method: 'get',
url: 'http://localhost:8080/static/mock/data.json'
}).then(resp=>{
console.log(resp.data)}
)
}
}
Clicking on personal information will trigger hook function , get data 
Project structure

边栏推荐
- TDSQL-C Serverless:助力初创企业实现降本增效
- Click El dropdown item/@click.native
- 从标注好的xml文件中截取坐标点(人脸框四个点坐标)人脸图像并保存在指定文件夹
- 银行业客户体验管理现状与优化策略分析
- [oauth2] VIII. Configuration logic of oauth2 login -oauth2loginconfigurer and oauth2clientconfigurer
- 421. 数组中两个数的最大异或值
- The use of asynchronous thread pool in development
- Research status and pain points of deep learning 3D human posture estimation at home and abroad
- Official announcement! Edweisen group and Baidu xirang reached a deep co creation cooperation
- Hcip day 11 comparison (BGP configuration and release)
猜你喜欢

Ultimate doll 2.0 | cloud native delivery package

Unity中序列化类为json格式

Activity.onStop() 延迟10秒?精彩绝伦的排查历程

Tianjin emergency response Bureau and central enterprises in Tianjin signed an agreement to deepen the construction of emergency linkage mechanism

Analysis on the current situation and optimization strategy of customer experience management in banking industry

See you tomorrow at the industrial session of cloud intelligence technology forum!

Target detection network r-cnn series

HCIP第十二天笔记整理(BGP联邦、选路规则)

详解关系抽取模型 CasRel

多线程使用不当导致的 OOM
随机推荐
Sword finger offer (IX): abnormal jumping steps
重押海外:阿里、京东、顺丰再拼“内力”
Segmentation fault (core dumped)
Team research and development from ants' foraging process (Reprint)
Probability theory and mathematical statistics
JS object assignment problem
JUC总结
Implementation of SAP ABAP daemon
Comparison between SIGMOD function and softmax function
How to face scientific and technological unemployment?
如何构建以客户为中心的产品蓝图:来自首席技术官的建议
El table implements editable table
数据泄漏、删除事件频发,企业应如何构建安全防线?
Solve the problem that the remote host cannot connect to the MySQL database
【开源之美】nanomsg(2) :req/rep 模式
Can I take your subdomain? Exploring Same-Site Attacks in the Modern Web
Jenkins 中 shell 脚本执行失败却不自行退出
With 8 years of product experience, I have summarized these practical experience of continuous and efficient research and development
Pytoch learning notes (III) use, modification, training (cpu/gpu) and verification of the model
JSON data transfer parameters & date type parameter transfer