app.ts
public static MvcHtmlString Field<TModel, TItem>(this HtmlHelper<TModel> html, Expression<Func<TModel, TItem>> expr)
{
var h = "<div class='form-group'>";
h += $"{html.LabelFor(expr)}{html.EditorFor(expr)}{html.ValidationMessageFor(expr)}";
h += "</div>";
return MvcHtmlString.Create(h);
}
app.routing.ts
import './sass/style.scss'
import 'reflect-metadata'
import 'zone.js/dist/zone.min.js';
import { Component, NgModule } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'
import { BrowserModule } from '@angular/platform-browser';
import { RootComponent } from './components/root.component';
import { RegistrationComponent } from './components/registration.component';
import { routing } from './app.routing';
@NgModule({
declarations: [
RootComponent,
RegistrationComponent
],
imports: [
BrowserModule,
routing
],
providers: [],
bootstrap: [RootComponent]
})
export class AppModule {}
platformBrowserDynamic().bootstrapModule(AppModule);
route.component.ts
import { RouterModule, Routes } from '@angular/router';
import { RegistrationComponent } from './components/registration.component';
const APP_ROUTES: Routes = [
{ path: '', redirectTo: '/registration', pathMatch: 'full' },
{ path: 'registration', component: RegistrationComponent }
];
export const routing = RouterModule.forRoot(APP_ROUTES);
答案 0 :(得分:1)
我修好了。我必须将{ useHash: true}
添加到我的路由中。
export const routing = RouterModule.forRoot(APP_ROUTES, { useHash: true});
现在可行:D
答案 1 :(得分:0)
您可能需要一个网络服务器重写机制:Angular知道如何处理/registration
,但您的网络服务器却没有。这意味着您需要配置您的网络服务器以将对不存在的文件的请求传递给Angular,即index.html
(或任何您的Ang2起点)。
假设您使用Apache,最简单的事情是:
FallbackResource /index.html
或者(或者如果您使用的服务器不支持此类内容),您可以切换到Angular的HashLocationStrategy
。