【问题标题】:Routing in vue js 404 pagevue js 404页面中的路由
【发布时间】:2021-05-02 13:45:47
【问题描述】:

伙计们,所以基本上我有我的 routes.js 文件,显然我的路由在其中,但我正在尝试添加另一个路由,如果用户尝试访问不在我的应用程序上的路由,它将重定向到 404 页面

{ path: '*', component: require('./components/NotFound.vue') }

这是我的 route.js 文件


import VueRouter from 'vue-router'
Vue.use(VueRouter)

import dashboard from './components/Dashboard'
import profile from './components/Profile'
import user from './components/Users'
import unauthorized from './components/Unauthorized'

/**
 *
 *
     better run npm run watch or your routes will not work
     also the main page is the one with the id="app"
     dont forget to add a link in that main page to app.js
     <script src="{{ asset('js/app.js') }}" defer></script>
 *
 *
 */

let routes = [
        {
            path: '/dashboard',
            component: dashboard
        },
        {
            path: '/profile',
            component: profile
        },
        {
            path: '/users',
            component: user
        },
        {
            path: '/unauthorized',
            component: unauthorized,
            name: unauthorized
        },
        {
            path: '*',
            component: 404
        }


]






export default new VueRouter({
    mode: 'history',
    routes
})

这就是我写的,它给了我错误并且不起作用,请需要帮助

谢谢

【问题讨论】:

    标签: laravel vue.js


    【解决方案1】:

    没有导入404 组件。 也别叫404,叫PageNotFound.vue

    【讨论】:

    • 兄弟,你错过了一个组件的完整导入
    • 是的 404 页面正确的导入,你的意思是这个 ``` import 404 from './components/404' ,这也是一个错误
    • 将其重命名为 PageNotFound 而不是 404。否则错误说明了什么?
    • 是的,它可以工作,但也许你不明白我在说什么,当有人搜索未知 url 时,它应该显示 PageNotFound,我该怎么做?
    【解决方案2】:

    所以我实际上解决了解决方案的错误

    首先包含我的 vue 文件 import notfound from './components/Notfound' 然后将其添加到我的路径中

    {
                path: '*',
                component: notfound
            }
    

    【讨论】:

    • 兄弟。这正是我告诉你的。 there is no 404 component imported 就是这个意思!
    猜你喜欢
    • 2019-01-08
    • 1970-01-01
    • 2023-01-26
    • 2019-01-09
    • 1970-01-01
    • 1970-01-01
    • 2018-02-27
    • 2019-08-02
    • 2017-01-19
    相关资源
    最近更新 更多