這是我在角JS 2 MVC4.5應用routing.ts角JS 2 MVC 4.5在瀏覽器的URL按Enter鍵顯示404個
import { ModuleWithProviders } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { HomeComponent } from './components/home/home.component';
import { CarsComponent } from './components/cars/cars.component';
const appRoutes: Routes = [
{
path: 'home',
component: HomeComponent
},
{
path: 'cars',
component: CarsComponent
},
{
path: '',
redirectTo: '/home',
pathMatch: 'full'
},
];
export const routing: ModuleWithProviders = RouterModule.forRoot(appRoutes);
這工作得很好,但我按http://localhost:3000/cars進入
它會顯示一個404錯誤頁面
它在服務器上搜索localhost:3000/cars並且服務器沒有這個端點如何解決這個問題?
在服務器側的服務器側WebApiConfig
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
// Web API configuration and services
// Web API routes
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}
}
每次請你從瀏覽器發送服務器進行處理。當您按下地址欄中的回車鍵時,它會將請求發送到服務器。但是你在服務器中沒有'/ cars'路徑。這就是爲什麼它顯示404錯誤。 –
@ ti2005嗯尋找一個解決這個問題 – Kalanamith