2017-10-26 6 views
0

の歴史は、私はアプリのURLからハッシュ(#)を取り除くしたい:ページは、ルータモードでロードされない:Apacheの

http://localhost/CoreUI-Vue/Vue_Starter/dist/#/dashboardhttp://localhost/CoreUI/Vue_Starter/dist/dashboard

ので、私はvue-routermodeオプションを変更しましたhashからrouter/index.jshistoryへ:

import Vue from 'vue' 
import Router from 'vue-router' 

Vue.use(Router) 

export default new Router({ 
    mode: 'history', 

が、その後、私はrecompilとき私は実現

<body class="app header-fixed sidebar-fixed aside-menu-fixed aside-menu-hidden"> 
<div class="app"> 
    (...app content...) 
</div> 
<script type="text/javascript" src="./static/js/manifest.a2cf3e09f095de958e46.js"></script> 
<script type="text/javascript" src="./static/js/vendor.dfb9d96e757ce802aece.js"></script> 
<script type="text/javascript" src="./static/js/app.72b651a6c3b2660db094.js"></script> 
</body> 

:問題なくアプリmode: 'hash'http://localhost/CoreUI/Vue_Starter/dist/#/dashboard)負荷でルータのに対し

<body class="app header-fixed sidebar-fixed aside-menu-fixed aside-menu-hidden"> 
<!----> 
<script type="text/javascript" src="./static/js/manifest.7c717a1bcc0cc7dc29c1.js"></script> 
<script type="text/javascript" src="./static/js/vendor.dfb9d96e757ce802aece.js"></script> 
<script type="text/javascript" src="./static/js/app.1cbf93c84add6c85b943.js"></script> 
</body> 

:ソースコード(npm run buildを)編とアプリ(http://localhost/CoreUI/Vue_Starter/dist/dashboard)を開いて、それが空のページをロードこの追加の設定は、これを動作させるためにWebサーバーに提供する必要がありますが、それでも私を助けてくれませんでした。私は(vue-router docsからコピー).htaccessにおける歴史ルータのサポートを提供

LoadModule rewrite_module modules/mod_rewrite.so 

<IfModule mod_rewrite.c> 
    RewriteEngine On 
    RewriteBase/
    RewriteRule ^index\.html$ - [L] 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteRule . /index.html [L] 
</IfModule> 

.htaccessは同じに位置している私はmod_rewriteのがオンになっている保証はApacheのconfig httpd.conf

フォルダをプロジェクトのindex.htmlとして保存します。

私は空で作業していますCoreUI-Vue最も普及しているWebpack/Vue boilerplateを使用しているテンプレートなので、私のコードや設定については特別なことはありません。

+0

これを試すサーバーを持っていないのですが、 'RewriteBase'は'/CoreUI/Vue_Starter/dist/'にする必要があります。 –

答えて

1

プロダクションビルドを使用しています。

<VirtualHost *:80> 
    DocumentRoot "c:\path_to_dist" 

    ServerName servername.localhost 
</VirtualHost> 

/etc/hosts(Linux)またはc:\Windows\system32\drivers\etc\hosts(Windowsの場合)に追加します:私は、本番環境でのようなパスを持っているApacheの設定でのVirtualHostを追加すべきだと思う

127.0.0.1 servername.localhost 

私はあなたのためにこの方法を好みます任意のフレームワークマニュアルからすべての.htaccess設定を追加編集せずに使用することができ、パスの問題はありません。あなたはこのソリューションを使用しない場合は

もちろん

、あなたは.htaccessこのようなものにすることを編集することができます(年からはApacheを使用しなかった)

<IfModule mod_rewrite.c> 
    RewriteEngine On 
    RewriteBase/
    RewriteRule ^index\.html$ - [L] 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteRule . CoreUI/Vue_Starter/dist/index.html [L] 
</IfModule> 

私はそれが動作するかどうかわからないんだけど、私はあなたがその最後のRewriteRuleまたはRewriteBaseを編集しなければならないと確信しています。

関連する問題