1
我有Spring Boot Application(後端),前端我使用的是Angular 2 Single Page Application。刷新後的白標籤錯誤頁面
每當我導航到一個路線,例如:localhost:8080/getAccounts,並做導航刷新後,我得到白色標籤錯誤頁面。如果我在根本地主機:8080我工作正常。該問題只發生在子鏈接中。
返回(使用返回/返回按鈕)到上一頁也工作正常。只是刷新。
我也不能直接調用鏈接:localhost:8080/getAccounts。首先,我必須回家(本地主機:8080)呼叫通過子導航欄的頁面。
有沒有人有同樣的問題?我不得不改變什麼樣的矛盾。我的代碼:
Main.ts
import {bootstrap} from '@angular/platform-browser-dynamic';
import {AppComponent} from './components/app.component';
import {HTTP_PROVIDERS};
import {enableProdMode} from '@angular/core';
enableProdMode();
bootstrap(AppComponent, [HTTP_PROVIDERS]);
app.comonent:
import { Component, OnInit } from '@angular/core';
import { Http } from '@angular/http';
import { RouteConfig, ROUTER_DIRECTIVES, ROUTER_PROVIDERS } from '@angular/router-deprecated';
import { HomeComponent } from './home.component';
import { UserSearchComponent} from './webUserProfiles.component';
import { UserDetailViewComponent} from './webUserProfileView.component';
import { HTTPService } from '../service/http.service';
@Component({
selector: 'app-content',
templateUrl: './app/templates/app.component.html',
directives: [ROUTER_DIRECTIVES, AccessErrorComponent],
providers: [
ROUTER_PROVIDERS,
HTTPService
]
})
@RouteConfig([
{
path: '/',
name: 'HomeComponent,
useAsDefault: true
},
{
path: '/user',
name: 'UserSearch',
component: UserSearchComponent,
},
{
path: '/user/:id',
name: 'UserDetailView',
component: UserDetailViewComponent,
}
])
export class AppComponent implements OnInit {
constructor (
) { }
}
}
在此先感謝
首先謝謝你的回答。路由(Router_providers)在app.component中的應用程序中,而不在main.ts中。在main.ts中,我只有bootstrap(MyApp,[HTTP_PROVIDERS]);並沒有ROUTER_PROVIDERS。它有什麼區別? – trap
好吧,它的工作。非常感謝你!!! – trap
只要有人考慮實施該策略:角度文檔特別警告不要使用散列路由策略,如果您打算使用任何服務器端的重新加載來加速加載時間。哈希路由會阻止它工作。 https://angular.io/guide/router#appendix-locationstrategy-and-browser-url-styles – David