将 Laravel 7 和 Vue SPA 应用程序部署到共享主机中
Deploying Laravel 7 and Vue SPA application into shared hosting
各位专家,
我的应用程序有 Vue 前端和 Laravel 7 后端。问题是,我无法重定向到登录页面,它显示了一个空白屏幕。所有 Vue 文件都位于 resource/js 文件夹中。前后端没有单独的文件夹。
网络选项卡
控制台日志
文件夹结构:
- 根目录有quickpack文件夹
- 在 public_html 文件夹中有我的 Laravel 应用程序的 public 文件
到目前为止我做了什么:
AppServiceProvider.php
public function boot()
{
$this->app->bind('path.public', function() {
return base_path().'/../public_html/netlinkler/quickpack';
});
}
app.js
require('./bootstrap');
window.Vue = require('vue')
import store from './store'
import router from './router'
import ViewUI from 'view-design';
import 'view-design/dist/styles/iview.css';
Vue.use(ViewUI);
import common from './common';
Vue.mixin(common);
Vue.component('mainapp', require('./components/mainapp.vue').default)
const app = new Vue({
el: '#hmp',
router,
store
});
welcome.blade.php
<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Delivery App</title>
<link rel="stylesheet" href="{{asset('/css/all.css')}}">
</head>
<body>
<div id="hmp">
@if(Auth::guard('employee')->check())
<mainapp :user="{{Auth::guard('employee')->user()}}"></mainapp>
@else
<mainapp :user="false"></mainapp>
@endif
</div>
</body>
<script src="{{ mix('/js/app.js') }}"> </script>
</html>
EmployeeControler.php
public function index(Request $request){
if(!Auth::guard('employee')->check() && $request->path() != 'login'){
return redirect('/login');
}
if(!Auth::guard('employee')->check() && $request->path() == 'login'){
return view('welcome');
}
return view('welcome');
}
web.php
Route::get('/', 'EmployeesController@index');
Auth::routes();
router.js
const routes = [
{
path: '/home',
component: home
},
{
path: '/login',
component: login
}
]
export default new Router({
mode: "history",
baseurl: "/api/v1",
base: 'deliverywebapp',
routes
})
您需要将您的应用程序文件夹添加到您的路由路径
或者您可以添加基本路径
导出默认新路由器({
mode: "history",
baseurl: "/api/v1",
base: 'deliverywebapp',
常量路由=[
{
path: '/home',
component: home
},
{
path: '/login',
component: login
}
]
})
或
导出默认新路由器({
mode: "history",
baseurl: "/api/v1",
常量路由=[
{
path: '/deliverywebapp/home',
component: home
},
{
path: '/deliverywebapp/login',
component: login
}
]
})
各位专家, 我的应用程序有 Vue 前端和 Laravel 7 后端。问题是,我无法重定向到登录页面,它显示了一个空白屏幕。所有 Vue 文件都位于 resource/js 文件夹中。前后端没有单独的文件夹。
网络选项卡
控制台日志
- 根目录有quickpack文件夹
- 在 public_html 文件夹中有我的 Laravel 应用程序的 public 文件
到目前为止我做了什么:
AppServiceProvider.php
public function boot()
{
$this->app->bind('path.public', function() {
return base_path().'/../public_html/netlinkler/quickpack';
});
}
app.js
require('./bootstrap');
window.Vue = require('vue')
import store from './store'
import router from './router'
import ViewUI from 'view-design';
import 'view-design/dist/styles/iview.css';
Vue.use(ViewUI);
import common from './common';
Vue.mixin(common);
Vue.component('mainapp', require('./components/mainapp.vue').default)
const app = new Vue({
el: '#hmp',
router,
store
});
welcome.blade.php
<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Delivery App</title>
<link rel="stylesheet" href="{{asset('/css/all.css')}}">
</head>
<body>
<div id="hmp">
@if(Auth::guard('employee')->check())
<mainapp :user="{{Auth::guard('employee')->user()}}"></mainapp>
@else
<mainapp :user="false"></mainapp>
@endif
</div>
</body>
<script src="{{ mix('/js/app.js') }}"> </script>
</html>
EmployeeControler.php
public function index(Request $request){
if(!Auth::guard('employee')->check() && $request->path() != 'login'){
return redirect('/login');
}
if(!Auth::guard('employee')->check() && $request->path() == 'login'){
return view('welcome');
}
return view('welcome');
}
web.php
Route::get('/', 'EmployeesController@index');
Auth::routes();
router.js
const routes = [
{
path: '/home',
component: home
},
{
path: '/login',
component: login
}
]
export default new Router({
mode: "history",
baseurl: "/api/v1",
base: 'deliverywebapp',
routes
})
您需要将您的应用程序文件夹添加到您的路由路径
或者您可以添加基本路径
导出默认新路由器({
mode: "history",
baseurl: "/api/v1",
base: 'deliverywebapp',
常量路由=[
{
path: '/home',
component: home
},
{
path: '/login',
component: login
}
]
})
或
导出默认新路由器({
mode: "history",
baseurl: "/api/v1",
常量路由=[
{
path: '/deliverywebapp/home',
component: home
},
{
path: '/deliverywebapp/login',
component: login
}
]
})