update
This commit is contained in:
@@ -8,45 +8,51 @@ import {
|
||||
import routes from './routes'
|
||||
import { useProjectsStore } from 'stores/projects'
|
||||
import { useAuthStore } from 'stores/auth'
|
||||
import { parseStartParams } from 'helpers/helpers'
|
||||
|
||||
export default defineRouter(function (/* { store, ssrContext } */) {
|
||||
const createHistory = process.env.SERVER
|
||||
? createMemoryHistory
|
||||
: (process.env.VUE_ROUTER_MODE === 'history' ? createWebHistory : createWebHashHistory)
|
||||
|
||||
const Router = createRouter({
|
||||
const startRouteInfo = typeof window !== 'undefined' && window.Telegram?.WebApp?.initDataUnsafe?.start_param
|
||||
? parseStartParams(window.Telegram.WebApp.initDataUnsafe.start_param)
|
||||
: null
|
||||
|
||||
const Router = createRouter({
|
||||
scrollBehavior: () => ({ left: 0, top: 0 }),
|
||||
routes,
|
||||
|
||||
// Leave this as is and make changes in quasar.conf.js instead!
|
||||
// quasar.conf.js -> build -> vueRouterMode
|
||||
// quasar.conf.js -> build -> publicPath
|
||||
history: createHistory(process.env.VUE_ROUTER_BASE),
|
||||
history: createHistory(process.env.VUE_ROUTER_BASE)
|
||||
})
|
||||
|
||||
Router.beforeEach(async (to) => {
|
||||
|
||||
if (to.name === 'settings') return
|
||||
if (to.name === '404') return
|
||||
|
||||
const authStore = useAuthStore()
|
||||
console.log(window.Telegram.WebApp.initDataUnsafe.start_param, startRouteInfo)
|
||||
console.log(112, to)
|
||||
if (to.name === 'settings' || to.name === '404' || to.name === 'accept-terms') return true
|
||||
const authStore = useAuthStore()
|
||||
const projectsStore = useProjectsStore()
|
||||
|
||||
|
||||
if (authStore.startRouteInfo && to.path === '/') {
|
||||
const { id, taskId, meetingId } = authStore.startRouteInfo
|
||||
authStore.setStartRouteInfo(null)
|
||||
|
||||
if (!projectsStore.isInit) await projectsStore.init()
|
||||
const project = projectsStore.projectById(id)
|
||||
if (!authStore.isInit) await authStore.init(window.Telegram.WebApp)
|
||||
// if (!authStore.isTermsAccepted) return { name: 'accept-terms' }
|
||||
|
||||
if (!project) return { name: '404' }
|
||||
if (to.path === '/' && startRouteInfo) {
|
||||
console.log(222, startRouteInfo)
|
||||
const { id, taskId, meetingId } = startRouteInfo
|
||||
|
||||
return taskId
|
||||
? { name: 'task_info', params: { id, taskId } }
|
||||
: meetingId
|
||||
? { name: 'meeting_info', params: { id, meetingId } }
|
||||
: { name: 'files', params: { id } }
|
||||
if (!projectsStore.isInit) await projectsStore.init()
|
||||
|
||||
const project = projectsStore.projectById(id)
|
||||
if (!project) return { name: '404' }
|
||||
|
||||
return taskId
|
||||
? { name: 'task_info', params: { id, taskId } }
|
||||
: meetingId
|
||||
? { name: 'meeting_info', params: { id, meetingId } }
|
||||
: { name: 'files', params: { id } }
|
||||
}
|
||||
|
||||
if (to.params.id) {
|
||||
|
||||
Reference in New Issue
Block a user