Skip to content

Commit

Permalink
fix: Use dynamic base URL for vue router to make routing work in all …
Browse files Browse the repository at this point in the history
…cases

Signed-off-by: Julius Knorr <[email protected]>
  • Loading branch information
juliusknorr authored and grnd-alt committed Feb 11, 2025
1 parent bf613dd commit 8314ca7
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import Vue from 'vue'
import Router from 'vue-router'
import { generateUrl } from '@nextcloud/router'
import { generateUrl, getRootUrl } from '@nextcloud/router'
import { BOARD_FILTERS } from './store/main.js'
import Boards from './components/boards/Boards.vue'
import Board from './components/board/Board.vue'
Expand All @@ -16,9 +16,15 @@ import Overview from './components/overview/Overview.vue'

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({
mode: 'history',
base: generateUrl('/apps/deck/'),
base: currentBaseUrl,
linkActiveClass: 'active',
routes: [
{
Expand Down Expand Up @@ -145,7 +151,7 @@ const router = new Router({
router.beforeEach((to, from, next) => {
// Redirect if fullPath begins with a hash (ignore hashes later in path)
if (to.hash.substring(0, 2) === '#/') {
const path = to.fullPath.replace('/apps/deck/#/', '/apps/deck/')
const path = to.fullPath.replace('/#/', '/').trimEnd('/')
next(path)
return
}
Expand Down

0 comments on commit 8314ca7

Please sign in to comment.