将Laravel 7和Vue SPA应用程序部署到共享托管中

时间:2020-08-11 15:29:08

标签: laravel vue.js single-page-application vue-router shared-hosting

专家, 我的应用程序具有Vue前端和Laravel 7后端。问题是,我无法重定向到登录页面,它显示了一个空白屏幕。所有Vue文件都位于resource / js文件夹中。前端和后端没有单独的文件夹。

“网络”标签

enter image description here

控制台日志

enter image description here 文件夹结构:

  • 根目录具有 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
})

1 个答案:

答案 0 :(得分:1)

您需要将应用程序文件夹添加到路由路径

或者您可以添加基本路径

导出默认的新路由器({

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 
}

]

})