내가 읽고 404 오류가 무엇입니까 그러나 때 각도 (2)를 사용하여 홈페이지에서 다른 화면으로 경로에 노력하고 안녕하세요 :각도 2 라우팅 404 오류
가 (찾을 수 없음) http://localhost:5000/map/1 404 GET
을응용 프로그램은 ASP.NET 코어를 백엔드에 통합합니다.
두 질문 :
(1) 내가 필요하십니까
같은[Route("api/map")]
public IActionResult Map()
{
return View();
}
(2) 내 각 라우팅에 문제가 말한다뿐만 아니라 MVC 컨트롤러의 방법은?
가 app.module.ts
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { UniversalModule } from 'angular2-universal';
import { AppComponent } from './components/app/app.component'
import { NavMenuComponent } from './components/navmenu/navmenu.component';
import { HomeComponent } from './components/home/home.component';
import { FetchDataComponent } from './components/fetchdata/fetchdata.component';
import { MapComponent } from './components/map/map.component';
const appRoutes: Routes = [
{ path: '', redirectTo: 'home', pathMatch: 'full' },
{ path: 'home', component: HomeComponent },
{ path: 'map/:id', component: MapComponent },
{ path: 'fetch-data', component: FetchDataComponent },
{ path: '**', redirectTo: 'home' }
];
@NgModule({
bootstrap: [AppComponent],
declarations: [
AppComponent,
NavMenuComponent,
MapComponent,
FetchDataComponent,
HomeComponent
],
imports: [
UniversalModule,
RouterModule.forRoot(appRoutes)
]
})
export class AppModule {
}
map.component.ts
import { Component, OnInit } from '@angular/core';
import { MapService } from './../map.service';
@Component({
selector: 'map-root',
templateUrl: 'map.component.html',
providers: [MapService]
})
export class MapComponent implements OnInit {
constructor(public _mapService: MapService) { }
public images: [any];
ngOnInit() {
}
}
map.component.html
<h1>This is a test</h1>
에 Index.html
@{
ViewData["Title"] = "Home Page";
}
<base href="/" />
<app class="container" style="display: block;">Loading...</app>
<script src="~/dist/vendor.js" asp-append-version="true"></script>
@section scripts {
<script src="~/dist/main-client.js" asp-append-version="true"></script>
}
의 Web.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<!--
Configure your application settings in appsettings.json. Learn more at https://go.microsoft.com/fwlink/?LinkId=786380
-->
<system.webServer>
<rewrite>
<rules>
<rule name="AngularJS Routes" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_URI}" pattern="^/(api)" negate="true" />
</conditions>
<action type="Rewrite" url="/index.html" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
이것은 완벽합니다. 내 요소가 색인이 아닌 레이아웃보기에 있습니다. 그러나 귀하의 문서에 제안 된 코드를 구현했으며 오류가 발생했습니다. 내 게시물에 수정 사항을 추가했습니다. 어떤 통찰력도 훌륭합니다.Thx –
RyeGuy
안녕하세요 RyeGuy,이 일을 얻었습니까? 응용 프로그램을 서버로 옮긴 후 동일한 문제에 직면하고 있습니다. index.html에 접근하면 잘 작동합니다 : myserver.com/appVirtualDir/index.html'. 직접 경로 ('myserver.com/appVirtualDir/mainview')에 접근하려고하면 404가 표시됩니다. – Deepak