首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Vue-路由器页面刷新或URL访问

Vue-路由器页面刷新或URL访问
EN

Stack Overflow用户
提问于 2018-09-14 12:55:02
回答 2查看 3.5K关注 0票数 1

我有一个登陆页面注册/登录,从该重定向到主页的内容。成功登录后,我重定向如下:

代码语言:javascript
复制
this.$router.push({ name: 'main' })

这是可行的,但是如果我刷新页面或者尝试从url访问它--比如http://testapp.test/main --我得到了错误:页面不存在。目前,我没有任何保护,以防止访问页面,只有登录用户,我也添加了‘*’路径路由器为未定义的路由,它也只是抛出404,而不是加载主页。以下是我的路由器设置:

代码语言:javascript
复制
import Vue from 'vue'
import VueRouter from 'vue-router'
import BootstrapVue from 'bootstrap-vue'
import {store} from './store/store'

Vue.use(BootstrapVue);
Vue.use(VueRouter);

window.Vue = require('vue');


import Home from './components/LandingPage.vue'
import Main from './components/MainPage.vue'
import Logout from './components/Logout.vue'

const router = new VueRouter({
    mode: 'history',
    routes: [
        {
            path: '/',
            name: 'home',
            component: Home,
        },
        {
            path: '/main',
            name: 'main',
            component: Main,
        },
        {
            path: '/logout',
            name: 'logout',
            component: Logout,
        },
        {
            path :'*',
            name: 'home',
            component: Home,
        }
    ],
});


const app = new Vue({
    el: '#app',
    components: { Home, Main, Logout },
    router,
    store,
});

我试过用https://router.vuejs.org/guide/essentials/history-mode.html#example-server-configurations,但我不确定我做得对不对。我所做的是复制的代码,并用它替换.htaccess中的现有代码。但是,即使是从登录路由停止工作,如果我访问/main,它会给我404个错误。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2018-09-17 10:59:27

我用加法

代码语言:javascript
复制
Route::get('/{vue_capture?}', function () { return view('welcome'); })->where('vue_capture', '[\/\w\.-]*');

进入web.php文件

票数 1
EN

Stack Overflow用户

发布于 2018-09-14 12:59:31

您还必须对此进行服务器端配置。作为一种选择,您可以尝试其他路由器模式吗?像“哈希”

下面是模式和服务器配置的文档。

https://router.vuejs.org/api/#mode

https://router.vuejs.org/guide/essentials/history-mode.html#example-server-configurations

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52332483

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档