我有一个登陆页面注册/登录,从该重定向到主页的内容。成功登录后,我重定向如下:
this.$router.push({ name: 'main' })这是可行的,但是如果我刷新页面或者尝试从url访问它--比如http://testapp.test/main --我得到了错误:页面不存在。目前,我没有任何保护,以防止访问页面,只有登录用户,我也添加了‘*’路径路由器为未定义的路由,它也只是抛出404,而不是加载主页。以下是我的路由器设置:
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个错误。
发布于 2018-09-17 10:59:27
我用加法
Route::get('/{vue_capture?}', function () { return view('welcome'); })->where('vue_capture', '[\/\w\.-]*');进入web.php文件
发布于 2018-09-14 12:59:31
您还必须对此进行服务器端配置。作为一种选择,您可以尝试其他路由器模式吗?像“哈希”
下面是模式和服务器配置的文档。
https://router.vuejs.org/api/#mode
https://router.vuejs.org/guide/essentials/history-mode.html#example-server-configurations
https://stackoverflow.com/questions/52332483
复制相似问题