2017-10-30 3 views
0

はURLから#を削除するには、生産モードでURLから#を削除し、私はapp.module.tsでこれをパットangular2

providers: [ 
       ..., 
       {provide: LocationStrategy, useClass: PathLocationStrategy}, 
       ... 

はlocalhost:4200 /カテゴリ

はlocalhost:4200 /#/カテゴリ

ローカルホストで

すべて

ng build --environment=prod --bh=/site/ --aot --no-sourcemap

このコマンドを使用して、うまく動作しますが、私は本番用にビルドする場合ファイルenviroment.prod.ts内

は私が持っている:

export const environment = { 
    production: true, 
    baseUrlBuilderMask: 'http://site_url/', 
    baseUrlApi: 'http://site_url/site/api/', 
    baseUrlAssets: 'http://site_url/site/assets/' 
} 

と私は、これが動作していない、オンラインサイトを試してみてください。

http://site_url/category

私に404エラーが発生します。

私はISS

を使用していて、私のweb.configファイルで私は変更する必要がどのような

<rewrite> 
<rules> 
<rule name="AngularJS" stopProcessing="true"> 
    <match url=".*" /> 
    <conditions logicalGrouping="MatchAll"> 
    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> 
    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> 
    </conditions> 
    <action type="Rewrite" url="/" /> 
</rule> 

がありますか?

+0

あなたの 'web.config'を投稿できますか? – Dhyey

+0

@DhyeyサーバーにURLを書き直すWeb設定部分を投稿しました – Martina

+0

@Dhyeyおそらく私はwebConfigを分割する必要がありますが、今は別の問題があります。https://stackoverflow.com/questions/47019087/iis-with-angular2-webapi -joomla – Martina

答えて

1

PathLocationStrategyはAngular2のデフォルトの場所戦略であり、#がURLに存在する場合は、その場所がどこかで上書きされている必要があります。

輸入:[ ... RouterModule RouterModule.forRootの2番目の引数として:{真useHash}モジュールプロバイダーの横に

、あなたのモジュールのインポートを確認し、それはまた提供することで上書きすることができます.forRoot(ルート、{useHash:真})の代わり ng build --environment=prod --bh=/site/ --aot --no-sourcemap

--bhの//第二引数 を削除]

+0

私はこのインポートを持っていません... – Martina

+0

多分私は私のwebConfigを分割する必要がありますが、今私は別の問題がありますhttps://stackoverflow.com/questions/47019087/iis-with-angular2-webapi-joomla – Martina

0

使用ng build --environment=prod --aot --no-sourcemapはindex.htmlをに設定するベースHREFを指定します。これを省略すると、プロダクションモードで動作します。

0

すべてのあなたのURLをindex.htmlにする必要があります。 html5モードを有効にすると、あなたのURLに#文字は使用されなくなります。 #記号は、サーバー側の構成を必要としないので便利です。 #がなければ、URLはもっと良く見えますが、サーバー側の書き換えも必要です follow this Link angular Ui routerとこれもangular issue

+0

多分私私のWebConfigを分割する必要がありますが、今は別の問題があります。https://stackoverflow.com/questions/47019087/iis-with-angular2-webapi-joomla – Martina