I am writing a single page application with angular2 and MVC5. I am new to both and am having problems with routing.
I would like to match the urls as:
/ → go to my index page which will load angular/api/{controller}/{id?} → REST API/{*anythingelse} → if the file exists there, return it as static content; otherwise, if angular can route it, angular its route; otherwise return 404.
The second point is quite simple, and I can configure client-side routing if I am willing to refuse 404 returns, but I cannot reconcile all this.
This seems to work:
app.UseStaticFiles(); app.UseMvc(routes => { routes.MapRoute( name: "api", template: "api/{controller}/{id?}"); routes.MapRoute( name: "spa", template: "{*anythingelse}", defaults: new { controller = "Home", action = "Index" }); });
and
@RouteConfig([ { path: "/", name: 'Splash', component: SplashView }, { path: '/accounts/login', name: 'Login', component: LoginView }, { path: '/accounts/register', name: 'Registration', component: RegistrationView }, { path: '/home/...', name: 'Home', component: HomeView }, ])
But it just serves as Index.cshtml for every request that is not a static file.
It seems to me that this is already a problem, but I could not find anything on the Internet. How to do it right?
I use "HTML5" types, not a hash style.
asp.net-core-mvc angular2-routing
Emdot
source share