Last active
July 11, 2020 01:10
-
-
Save coretravis/7a8dacab7c1db47261d2c2e2d7f2e138 to your computer and use it in GitHub Desktop.
Simple SPA .Net core Routing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Startup | |
{ | |
public void ConfigureServices(IServiceCollection services) | |
{ | |
} | |
public void Configure(IApplicationBuilder app, IWebHostEnvironment env) | |
{ | |
if (env.IsDevelopment()) | |
{ | |
app.UseDeveloperExceptionPage(); | |
} | |
app.Use(async (context, next) => | |
{ | |
// grab the request path | |
var path = context.Request.Path.HasValue ? context.Request.Path.Value : null; | |
// check if the request is for a file | |
var isAFile = Path.HasExtension(path); | |
if (!isAFile) | |
{ | |
// return the default page if its just a path and not a file | |
context.Request.Path = "/index.html"; | |
} | |
await next(); | |
}); | |
app.UseDefaultFiles(); | |
app.UseStaticFiles(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment