fix: 改用hash路由解决SPA回退到首页问题 + 修复登录API响应解析
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { createRouter, createWebHistory } from 'vue-router'
|
import { createRouter, createWebHashHistory } from 'vue-router'
|
||||||
import Home from '@/views/Home.vue'
|
import Home from '@/views/Home.vue'
|
||||||
import AdminLayout from '@/views/admin/AdminLayout.vue'
|
import AdminLayout from '@/views/admin/AdminLayout.vue'
|
||||||
import AdminDashboard from '@/views/admin/Dashboard.vue'
|
import AdminDashboard from '@/views/admin/Dashboard.vue'
|
||||||
@@ -8,7 +8,7 @@ import AdminSettings from '@/views/admin/Settings.vue'
|
|||||||
import AdminLogin from '@/views/admin/Login.vue'
|
import AdminLogin from '@/views/admin/Login.vue'
|
||||||
|
|
||||||
const router = createRouter({
|
const router = createRouter({
|
||||||
history: createWebHistory(),
|
history: createWebHashHistory(),
|
||||||
routes: [
|
routes: [
|
||||||
{ path: '/', name: 'home', component: Home },
|
{ path: '/', name: 'home', component: Home },
|
||||||
{ path: '/admin/login', name: 'login', component: AdminLogin },
|
{ path: '/admin/login', name: 'login', component: AdminLogin },
|
||||||
|
|||||||
@@ -41,7 +41,8 @@ async function handleLogin() {
|
|||||||
loading.value = true
|
loading.value = true
|
||||||
try {
|
try {
|
||||||
const res = await authApi.login(form.value)
|
const res = await authApi.login(form.value)
|
||||||
store.setToken(res.data.token)
|
const token = res.result.token
|
||||||
|
store.setToken(token)
|
||||||
await store.fetchProfile()
|
await store.fetchProfile()
|
||||||
ElMessage.success('登录成功')
|
ElMessage.success('登录成功')
|
||||||
router.push('/admin/dashboard')
|
router.push('/admin/dashboard')
|
||||||
|
|||||||
Reference in New Issue
Block a user