vue-router之mode與404(七)

1、mode模式

代碼示例:

export default new Router({
    mode: 'history', //mode模式
    routes: [...]})

mode取值說明:
(1)histroy:URL就像正常的 url,示例:http://localhost:8080/home
(2)hash:默認值,會多一個“#”,示例:http://localhost:8080/#/home

2、404頁面設置

如果訪問的路由不存在,或者用戶輸入錯誤時,會有一個404友好的提示頁面,配置如下:
(1)在/src/router/index.js中加入如下代碼:

// 404{
    path: '*',
    component: () => import('@/components/404')}

(2)在src/components/404.vue中編寫如下代碼:

<template>
    <div class="hello">
        <h1>404 not found</h1>
    </div></template><script>export default {
    data () {
        return {

        }
    }}</script><style scoped></style>


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章