VueRouter在历史模式下无法正常工作 - Wordpress

时间:2018-05-21 09:53:51

标签: javascript wordpress .htaccess vue.js vue-router

我使用Vue项目作为Wordpress主题。我创建了一个简单的路由器但是当我启用mode: 'history'时,我收到了空白网站。我已尝试配置.htaccess文件,但没有任何效果。我的项目位于XAMPP htdocs目录的VueWP目录中。哈希一切正常。哪里出错了?



# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /VueWP/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /VueWP/index.php [L]
</IfModule>
# END WordPress
&#13;
&#13;
&#13;

这是我的VueRouter:

&#13;
&#13;
import Vue from 'vue';
import Router from 'vue-router';
import Main from '../Components/Main';
import ArticlePage from '../Components/ArticlePage';
import Page from '../Components/Page';

Vue.use(Router);

export default new Router({
    mode: 'history',
    routes: [
        {
            path: '/',
            name: 'Main',
            component: Main
        },
        {
            path: '/post/:url',
            name: 'ArticlePage',
            component: ArticlePage
        },
        {
            path: '/page/:url',
            name: 'Page',
            component: Page
        }
    ],

});
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

在路线文件中定义publicPath: '/'。希望它有效。

import Vue from 'vue';
import Router from 'vue-router';
import Main from '../Components/Main';
import ArticlePage from '../Components/ArticlePage';
import Page from '../Components/Page';

Vue.use(Router);

export default new Router({
    mode: 'history',
    routes: [
        {
            path: '/',
            publicPath: '/',
            name: 'Main',
            component: Main
        },
        {
            path: '/post/:url',
            publicPath: '/',
            name: 'ArticlePage',
            component: ArticlePage
        },
        {
            path: '/page/:url',
            publicPath: '/',
            name: 'Page',
            component: Page
        }
    ],

});