chore: add env var to use createWebHashHistory #3313

Closed
WofWca wants to merge 1 commits from WofWca/frontend:router-hash-hostory-env into main
2 changed files with 6 additions and 3 deletions

View File

@ -10,4 +10,5 @@
# SENTRY_AUTH_TOKEN=YOUR_TOKEN
# SENTRY_ORG=vikunja
# SENTRY_PROJECT=frontend-oss
# VIKUNJA_FRONTEND_BASE=/custom-subpath
# VIKUNJA_FRONTEND_BASE=/custom-subpath
# VITE_ROUTER_HISTORY_MODE_IS_HASH=false

View File

@ -1,4 +1,4 @@
import { createRouter, createWebHistory } from 'vue-router'
import { createRouter, createWebHashHistory, createWebHistory } from 'vue-router'
Review

Do you know if vite / esbuild is intelligent enough to only bundle only one of those two history implementations imports?

Because the information should be available at build time.
If not could we check if this is possible?

Do you know if vite / esbuild is intelligent enough to only bundle only one of those two history implementations imports? Because the information should be available at build time. If not could we check if this is possible?
Review

So what I mean is: in case esbuild isn't intelligent enough could we help it via some 'special syntax' ala:

(pseudocode)

import { createRouter } from 'vue-router'

if (import.meta.env.VITE_ROUTER_HISTORY_MODE_IS_HASH === 'true') {
  import { createWebHashHistory: createHistory } from 'vue-router'
} else {
  import { createWebHistory: createHistory } from 'vue-router'
}

and then

// [...]
history: createHistory(import.meta.env.BASE_URL),
// [...]
So what I mean is: in case esbuild isn't intelligent enough could we help it via some 'special syntax' ala: *(pseudocode)* ```ts import { createRouter } from 'vue-router' if (import.meta.env.VITE_ROUTER_HISTORY_MODE_IS_HASH === 'true') { import { createWebHashHistory: createHistory } from 'vue-router' } else { import { createWebHistory: createHistory } from 'vue-router' } ``` and then ```ts // [...] history: createHistory(import.meta.env.BASE_URL), // [...] ```
Review

Webpack is capable of eliminating unused imports. Not sure about others.

Webpack is capable of eliminating unused imports. Not sure about others.
import type { RouteLocation } from 'vue-router'
import {saveLastVisited} from '@/helpers/saveLastVisited'
@ -81,7 +81,9 @@ const EditTeamComponent = () => import('@/views/teams/EditTeam.vue')
const NewTeamComponent = () => import('@/views/teams/NewTeam.vue')
const router = createRouter({
history: createWebHistory(import.meta.env.BASE_URL),
history: import.meta.env.VITE_ROUTER_HISTORY_MODE_IS_HASH === 'true'
Review

So this will be replaced on build time but will still contain the complete import.

So this will be replaced on build time but will still contain the complete import.
? createWebHashHistory(import.meta.env.BASE_URL)
: createWebHistory(import.meta.env.BASE_URL),
scrollBehavior(to, from, savedPosition) {
// If the user is using their forward/backward keys to navigate, we want to restore the scroll view
if (savedPosition) {