EvanAgee / vuejs-wordpress-theme-starter

A WordPress theme with the guts ripped out and replaced with Vue.
https://vuewp.com/
1.6k stars 281 forks source link

Routing when in sub-directory #24

Closed ghost closed 6 years ago

ghost commented 6 years ago

Hi Evan, first of all thanks for the good work!

I am new to vue so I got a little issue when I try serving the application from a subdirectory. The home url is http://localhost/projects/fabiangeierblog/.

The header and footer are shown but inside <router-view></router-view> Home.vue is not displayed.

This is my .htaccess File in C:\xampp\htdocs\projects\fabiangeierblog:

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

And this is my approach solving the problem in the router/index.js (C:\xampp\htdocs\projects\fabiangeierblog\wp-content\themes\fabiangeierblog)

import Vue from 'vue'
import Router from 'vue-router'

// Components
import Home from '../components/Home'

Vue.use(Router)

const router = new Router({
  routes: [
    {
      path: '/',
      name: 'Home',
      component: Home,
      // props: { pageContentID: 383 }
    }
  ],
  base: "/projects/fabiangeierblog/",
  mode: 'history',
  scrollBehavior (to, from, savedPosition) {
    if (savedPosition) {
      return savedPosition
    } else {
      return { x: 0, y: 0 }
    }
  }
})

export default router

Thanks for the help and the good work you are doing.

Fabian

ghost commented 6 years ago

I realised that now everything works fine. I guess it was somehow server related.