Angular最终版本/版本2.0.1页面重新加载/刷新问题

问题描述 投票:0回答:1

我已使用以下代码在app.module.ts文件中尝试过LocationStrategy

    import { LocationStrategy, HashLocationStrategy } from '@angular/common';

    @NgModule({
        imports: [
            ...
        ],
        declarations: [
            ...
        ],
        bootstrap: [...],
        providers: [
            { provide: LocationStrategy, useClass: HashLocationStrategy }
        ]
    })

In app.component.ts file i have added below code
import {Location} from '@angular/common';

   export class AppComponent {
    constructor(location: Location) {
        location.go(location.path());
    }
}

但是如果刷新页面或按f5键时页面无法重新加载,而是导航到其他页面或同一页面时无法识别,而是出现404页面未找到错误。请您告诉我解决方案。

angular2-routing
1个回答
0
投票

在通过goolge找到许多解决方案后,我尝试使用php在我的角度应用程序中遇到了同样的问题,我尝试了这一方法-对我来说工作正常。

只需将.htaccess文件放入您的根目录并添加以下代码-

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.html [QSA,L]
</IfModule>
© www.soinside.com 2019 - 2024. All rights reserved.