2017-10-30 7 views
0

이 URL에서 #을 제거하려면 또한 생산 모드에서 URL에서 #을 제거 나는 app.module.ts이를 퍼트angular2

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

로컬 호스트 : 4200/카테고리

로컬 호스트 : 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 오류를 제공합니다. 내가

내 Web.config의에서 ISS

을 사용하고

나는 변경해야 할 무엇

<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 내가 @Dhyey 어쩌면 내가 내 webConfig을 분할해야하지만, 지금은 또 다른 문제가 서버 – Martina

+0

에 URL 재 작성을 수행하는 웹 설정 부분을 게시 https://stackoverflow.com/questions/47019087/iis-with-angular2-webapi -joomla – Martina

답변

1

PathLocationStrategy는 Angular2의 기본 위치 전략, 그리고 #은 URL에있는 경우, 그 어딘가에 대체 것 이었음에 틀림 없다.

수입 : [ ... RouterModule RouterModule.forRoot의 두 번째 인수로 : {사실 useHash} 모듈 공급자 옆에

, 모듈 수입을 확인, 그것은 또한 제공 오버라이드 (override) 할 수 있습니다 .forRoot (경로, {useHash : 사실은}) // 두 번째 인수 ]

+0

나는이 수입이없는 ... – Martina

+0

어쩌면 내 webConfig을 분할해야하지만 지금 나는 어쩌면 또 다른 문제 https://stackoverflow.com/questions/47019087/iis-with-angular2-webapi-joomla – Martina

0

사용 ng build --environment=prod --aot --no-sourcemap 대신 ng build --environment=prod --bh=/site/ --aot --no-sourcemap

--bh가 index.html을 설정해야 할 기본 href 지정을 제거합니다. 이를 생략하면 생산 모드로 작동합니다.

0

당신은 index.html을하는 모든 URL을 감소 할 필요가있다. html5 모드를 사용하도록 설정하면 # 문자가 더 이상 URL에 사용되지 않습니다. # 기호는 서버 측 구성이 필요하지 않으므로 유용합니다. #가 없으면 URL이 훨씬 더 멋지게 보이지만 서버 측 다시 쓰기가 필요합니다. follow this Link angular Ui router 및이 또한 angular issue

+0

가 내 webConfig를 분할해야하지만, 지금은 또 다른 문제가 https://stackoverflow.com/questions/47019087/iis-with-angular2-webapi-joomla – Martina