我使用路由器链接组件创建了一个vuejs项目。所有操作都在本地主机上工作,但在将项目部署到实时服务器时失败,在实时服务器上子域路径和路由器链接失败。
正确的路径应该是example.com/project_name/public/client,但它正在被example.com/client替换。
App.JS


let routes = [
    {path: '/dashboard', component: require('./components/dashboard.vue').default},
    {path: '/client', component: require('./components/client.vue').default},

]

const router = new VueRouter({
    mode: "history",
    routes
})

const app = new Vue({
    el: '#app',
    router
});


主刀片
<div class="page-wrapper" id="app">

  <li>
     <router-link to="/dashboard" title="Dashboard">
     <span class="nav-link-text"><i style="color:white"
       class="fal fa-tachometer-alt"></i>&nbsp;&nbsp; Dashboard</span>
     </router-link>
  </li>

  <li>
      <router-link to="/client" title="Client">
        <span class="nav-link-text"><i style="color:white" class="fal fa-users"></i>&nbsp;&nbsp; Client</span>
      </router-link>
  </li>

</div>


web.php网站
Route::prefix('api')->middleware('auth')->group(function () {

    Route::apiResource('clients', 'API\ClientController');

});


方法:

methods: {

    getClients() {
                axios.get('api/clients').then(({data}) => (this.clients = data.data));
            },
}

最佳答案

创建一个.htaccess文件并将其粘贴到根目录:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
<ifmodule mod_deflate.c>
AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x-javascript application/javascript
</ifmodule>

09-25 16:21