【问题标题】:Deploying Laravel 7 and Vue SPA application into shared hosting将 Laravel 7 和 Vue SPA 应用程序部署到共享主机中
【发布时间】:2020-12-01 07:29:17
【问题描述】:

专家, 我的应用程序有 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();

路由器.js

    const routes = [
    
        {
            path: '/home',
            component: home 
        },
        {
            path: '/login',
            component: login 
        }
    ]

export default new Router({
    mode: "history",
    baseurl: "/api/v1",
    base: 'deliverywebapp',
    routes
})

【问题讨论】:

  • laravel.log 中的任何内容?您能否也发布登录 POST 的 XHR 请求?
  • 嗨,lost.design。 XHR 请求中没有任何内容。
  • 您的控制台中有什么?从第一个屏幕截图中可以看出有 4 个错误。
  • lost.design 更新了问题。谢谢

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


【解决方案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 
}

]

})

【讨论】:

  • 我在 AppServiceProvider.php 中设置了公用文件夹路径。这还不够吗?
猜你喜欢
  • 1970-01-01
  • 2020-03-23
  • 2018-12-02
  • 2013-04-09
  • 1970-01-01
  • 1970-01-01
  • 2018-04-29
  • 2020-09-12
  • 1970-01-01
相关资源
最近更新 更多