Skip to content

Commit

Permalink
Fixes routing issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
KenEucker committed Jan 24, 2024
1 parent a832641 commit 15b76c6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 17 deletions.
4 changes: 3 additions & 1 deletion src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,9 @@ async function created() {
initResults.push(await store.fetchCurrentBikeTag())
if (game && routeIsHome) {
await router.push({ name: 'Home' })
const tagnumber = parseInt(router.currentRoute.value.path.split('/')[1]) ?? undefined
const params = { tagnumber }
await router.push({ name: 'Home', params })
}
initResults.push(store.fetchTags())
Expand Down
5 changes: 2 additions & 3 deletions src/components/BikeTagMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,9 @@ function onScroll() {
async function resetBikeTagApp() {
if (await isOnline()) {
store.resetBikeTagCache()
router.push({ name: 'Home' })
} else {
router.push('/')
}
router.push({ name: 'Home' })
}
function login() {
closeCollapsible()
Expand Down
26 changes: 13 additions & 13 deletions src/views/Home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -80,21 +80,16 @@ import { useI18n } from 'vue-i18n'
// data
const router = useRouter()
const route = useRoute()
let tagnumber = ref(route.params?.tagnumber ? parseInt(route.params.tagnumber) : 0)
const tagIsLoading = ref(true)
const store = useBikeTagStore()
const { t } = useI18n()
const tagnumber = computed(() => (route.params?.tagnumber ? parseInt(route.params.tagnumber) : 0))

// computed
const getCurrentBikeTag = computed(() => store.getCurrentBikeTag)
const getImgurImageSized = computed(() => store.getImgurImageSized)
const getTags = computed(() => store.getTags)

/// Support legacy webHashHistory urls
if (tagnumber.value === 0 && window.location.hash.indexOf('#/') === 0) {
tagnumber.value = parseInt(window.location.hash.split('#/')[1])
}

const tag = computed(() => {
if (tagnumber.value !== 0) {
const tag = getTags.value?.filter((t) => t.tagnumber === tagnumber.value)
Expand All @@ -108,21 +103,26 @@ function tagImageLoaded() {
tagIsLoading.value = false
}
function goNextSingle() {
tagnumber.value++
if (tagnumber.value === getCurrentBikeTag.value.tagnumber) {
tagnumber.value = 0
router.push('/')
} else {
router.push(`/${tagnumber.value}`)
router.push(`/${tagnumber.value + 1}`)
}
}
function goPreviousSingle() {
tagnumber.value = tagnumber.value > 0 ? tagnumber.value : getCurrentBikeTag.value.tagnumber
tagnumber.value--
router.push(`/${tagnumber.value}`)
const newTagnumber = tagnumber.value > 0 ? tagnumber.value : getCurrentBikeTag.value.tagnumber
router.push(`/${newTagnumber - 1}`)
}

// mounted
onMounted(() => (tagIsLoading.value = tagnumber.value === 0))
onMounted(async () => {
await router.isReady()
/// Support legacy webHashHistory urls
if (tagnumber.value === 0 && window.location.hash.indexOf('#/') === 0) {
tagnumber.value = parseInt(window.location.hash.split('#/')[1])
}
tagIsLoading.value = tagnumber.value === 0
})
</script>

<style lang="scss">
Expand Down

0 comments on commit 15b76c6

Please sign in to comment.