soybeanjs / soybean-admin

A clean, elegant, beautiful and powerful admin template, based on Vue3, Vite5, TypeScript, Pinia, NaiveUI and UnoCSS. 一个清新优雅、高颜值且功能强大的后台管理模板,基于最新的前端技术栈,包括 Vue3, Vite5, TypeScript, Pinia, NaiveUI 和 UnoCSS。

Home Page:https://soybeanjs.cn

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Bug]: Getting router is undefined when the page reloads after user logged

phpmathan opened this issue · comments

commented

Software Version

v1.1.0

Operating Environment

Ubuntu

Operating Architecture

AMD64

Reproduce Steps

After the user logged in, if the page reloads and uses static auth routes, then we get router is undefined error the page is not rendering because of no auth routes.

What is the expected result?

Replace the following import in src/store/modules/tab/index.ts

import { useRouter } from 'vue-router'; to import { router } from '@/router';

What is the actual result?

After replacing the router from 'vue-router' to '@/router' it is working fine, hence the behavior is same.

Logging (Optional)

No response

Additional Description (Optional)

No response

could you give me the more detail reproduction

commented

I've created the modular structure for easy code management and reuse the modules, and I initialize the modules before the setupRouter in main.ts, during the module initialization I prepare the static routes which internally call tabStore.initHomeTab() which triggered the error router is undefined.

20240514200107

20240514200255

Changing import { useRouter } from 'vue-router'; to import { router } from '@/router'; in src/store/modules/tab/index.ts solves my problem. I created this ticket for users like me who customize may see such issues, and these notes may help them.

ok, thanks, I'll do as you suggest.