当前位置:网站首页>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

边栏推荐
- 估值15亿美元的独角兽被爆裁员,又一赛道遇冷?
- Codeforces Round #810 (Div. 2)【比赛记录】
- 官宣!艾德韦宣集团与百度希壤达成深度共创合作
- Multi objective optimization series 1 --- explanation of non dominated sorting function of NSGA2
- Unicorn, valued at $1.5 billion, was suddenly laid off, and another track was cold?
- 向路由组件传递参数
- B+ tree index use (8) sorting use and precautions (20)
- 一文学透MySQL表的创建和约束
- How to write the introduction of GIS method journals and papers?
- Force deduction ----- the number of words in the string
猜你喜欢

Target detection network r-cnn series

银行业客户体验管理现状与优化策略分析

Official announcement! Edweisen group and Baidu xirang reached a deep co creation cooperation
![[shaders realize overlay to re cover cross dressing effect _shader effect Chapter 9]](/img/f3/48ca9e1e8889afc0993084d6416575.png)
[shaders realize overlay to re cover cross dressing effect _shader effect Chapter 9]

JSON数据传递参数&日期型参数传递

How to face scientific and technological unemployment?

Oom caused by improper use of multithreading

云智技术论坛工业专场 明天见!

多线程使用不当导致的 OOM

How to build a customer-centric product blueprint: suggestions from the chief technology officer
随机推荐
Leetcode 2119. number reversed twice
Oom caused by improper use of multithreading
消息的订阅和发布
MySQL data directory (1) -- database structure (24)
This article explains the FS file module and path module in nodejs in detail
图扑 3D 可视化国风设计 | 科技与文化碰撞炫酷”火花“
I. creation and constraint of MySQL table
Hcip day 12 notes sorting (BGP Federation, routing rules)
重押海外:阿里、京东、顺丰再拼“内力”
Time complexity analysis of bubble sorting
See you tomorrow at the industrial session of cloud intelligence technology forum!
The serialization class in unity is in JSON format
历时15年、拥有5亿用户的飞信,彻底死了
Unicode file parsing methods and existing problems
LeetCode 217. 存在重复元素
Leetcode 263. ugly number
The use of asynchronous thread pool in development
力扣------字符串中的单词数
Familiarize you with the "phone book" of cloud network: DNS
Leetcode 1523. count odd numbers within the interval