Laravel-Vuejs 应用程序不在实时域中 运行
Laravel-Vuejs App not running in live domain
我没有收到任何错误,但收到了一些警告:我正在共享应用程序登录页面的图像,它是一个完全空白的页面,但它在本地主机上运行良好:
代码来自 router.js
import { createRouter , createWebHistory } from 'vue-router'
import store from './store'
import website from './app/layout/website.vue'
import home from './app/website/frontpage.vue'
import hospitals from './app/website/hospitals.vue'
import notfound from './app/website/not_found.vue'
const routes = [
{
path : '/',
name : 'home',
component : home,
meta : { layout: website, visitor : true, requiresAuth : true}
},
{
path : '/hospitals',
name : 'hospitals',
component : hospitals,
meta : { layout: website, visitor : true, requiresAuth : true }
},
{
path: '/:pathMatch(.*)*',
name: 'notfound',
component: notfound,
meta: {layout: website, visitor : true}
}
]
var router = createRouter({
history : createWebHistory(process.env.BASE_URL),
routes
})
function loggedIn() {
return store.state.authenticated
}
router.beforeEach((to, from, next) => {
if(to.matched.some(record => record.meta.requiresAuth)) {
if(!loggedIn()) {
next({name : "login"})
}else{
next()
}
}else if(to.matched.some(record => record.meta.visitor)) {
if(loggedIn()) {
next({ name : "dashboard"})
}else{
next()
}
}else{
next()
}
})
export default router
我上传时没有任何 CRUD 系统,只有路由、应用程序、商店等和 html。
您需要将此代码编辑成这样
if(!loggedIn() && to.name!="login") { next({name : "login"}) }
else{ next() }
问题是即使在登录页面路由器也会重定向用户,这会造成无限循环
我没有收到任何错误,但收到了一些警告:我正在共享应用程序登录页面的图像,它是一个完全空白的页面,但它在本地主机上运行良好:
代码来自 router.js
import { createRouter , createWebHistory } from 'vue-router'
import store from './store'
import website from './app/layout/website.vue'
import home from './app/website/frontpage.vue'
import hospitals from './app/website/hospitals.vue'
import notfound from './app/website/not_found.vue'
const routes = [
{
path : '/',
name : 'home',
component : home,
meta : { layout: website, visitor : true, requiresAuth : true}
},
{
path : '/hospitals',
name : 'hospitals',
component : hospitals,
meta : { layout: website, visitor : true, requiresAuth : true }
},
{
path: '/:pathMatch(.*)*',
name: 'notfound',
component: notfound,
meta: {layout: website, visitor : true}
}
]
var router = createRouter({
history : createWebHistory(process.env.BASE_URL),
routes
})
function loggedIn() {
return store.state.authenticated
}
router.beforeEach((to, from, next) => {
if(to.matched.some(record => record.meta.requiresAuth)) {
if(!loggedIn()) {
next({name : "login"})
}else{
next()
}
}else if(to.matched.some(record => record.meta.visitor)) {
if(loggedIn()) {
next({ name : "dashboard"})
}else{
next()
}
}else{
next()
}
})
export default router
我上传时没有任何 CRUD 系统,只有路由、应用程序、商店等和 html。
您需要将此代码编辑成这样
if(!loggedIn() && to.name!="login") { next({name : "login"}) }
else{ next() }
问题是即使在登录页面路由器也会重定向用户,这会造成无限循环