X Tutup
Skip to content

Commit a83e4d8

Browse files
Show example of using traditional MVC controller+action routing alongside client-side routes
1 parent 8a0cbe7 commit a83e4d8

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

samples/angular/MusicStore/Startup.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,16 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerF
110110
// Add MVC to the request pipeline.
111111
app.UseMvc(routes =>
112112
{
113-
// Matches any request that doesn't appear to have a filename extension (defined as 'having a dot in the last URI segment').
113+
// Matches requests that correspond to an existent controller/action pair
114+
routes.MapRoute("default", "{controller}/{action}/{id:int?}");
115+
116+
// Matches any other request that doesn't appear to have a filename extension (defined as 'having a dot in the last URI segment').
114117
// This means you'll correctly get 404s for /some/dir/non-existent-image.png instead of returning the SPA HTML.
115118
// However, it means requests like /customers/isaac.newton will *not* be mapped into the SPA, so if you need to accept
116119
// URIs like that you'll need to match all URIs, e.g.:
117-
// routes.MapbackRoute("spa-fallback", "{*anything}", new { controller = "Home", action = "Index" });
118-
// (which of course will match /customers/isaac.png too - maybe that is a real customer name, not a PNG image).
120+
// routes.MapRoute("spa-fallback", "{*anything}", new { controller = "Home", action = "Index" });
121+
// (which of course will match /customers/isaac.png too, so in that case it would serve the PNG image at that URL if one is on disk,
122+
// or the SPA HTML if not).
119123
routes.MapSpaFallbackRoute("spa-fallback", new { controller = "Home", action = "Index" });
120124

121125
// Uncomment the following line to add a route for porting Web API 2 controllers.

0 commit comments

Comments
 (0)
X Tutup