fix: Use dynamic base URL for vue router to make routing work in all cases
Signed-off-by: Julius Knorr <jus@bitgrid.net>
This commit is contained in:
@@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
import Vue from 'vue'
|
import Vue from 'vue'
|
||||||
import Router from 'vue-router'
|
import Router from 'vue-router'
|
||||||
import { generateUrl } from '@nextcloud/router'
|
import { generateUrl, getRootUrl } from '@nextcloud/router'
|
||||||
import { BOARD_FILTERS } from './store/main.js'
|
import { BOARD_FILTERS } from './store/main.js'
|
||||||
import Boards from './components/boards/Boards.vue'
|
import Boards from './components/boards/Boards.vue'
|
||||||
import Board from './components/board/Board.vue'
|
import Board from './components/board/Board.vue'
|
||||||
@@ -16,9 +16,15 @@ import Overview from './components/overview/Overview.vue'
|
|||||||
|
|
||||||
Vue.use(Router)
|
Vue.use(Router)
|
||||||
|
|
||||||
|
// We apply a dynamic base URL depending on the URL used in the browser
|
||||||
|
const baseUrl = generateUrl('/apps/deck/')
|
||||||
|
const webRootWithIndexPHP = getRootUrl() + '/index.php'
|
||||||
|
const doesURLContainIndexPHP = window.location.pathname.startsWith(webRootWithIndexPHP)
|
||||||
|
const currentBaseUrl = doesURLContainIndexPHP ? baseUrl : baseUrl.replace('/index.php/', '/')
|
||||||
|
|
||||||
const router = new Router({
|
const router = new Router({
|
||||||
mode: 'history',
|
mode: 'history',
|
||||||
base: generateUrl('/apps/deck/'),
|
base: currentBaseUrl,
|
||||||
linkActiveClass: 'active',
|
linkActiveClass: 'active',
|
||||||
routes: [
|
routes: [
|
||||||
{
|
{
|
||||||
@@ -145,7 +151,7 @@ const router = new Router({
|
|||||||
router.beforeEach((to, from, next) => {
|
router.beforeEach((to, from, next) => {
|
||||||
// Redirect if fullPath begins with a hash (ignore hashes later in path)
|
// Redirect if fullPath begins with a hash (ignore hashes later in path)
|
||||||
if (to.hash.substring(0, 2) === '#/') {
|
if (to.hash.substring(0, 2) === '#/') {
|
||||||
const path = to.fullPath.replace('/apps/deck/#/', '/apps/deck/')
|
const path = to.fullPath.replace('/#/', '/').trimEnd('/')
|
||||||
next(path)
|
next(path)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user