Skip to content

Instantly share code, notes, and snippets.

@coretravis
Last active July 11, 2020 01:10
Show Gist options
  • Save coretravis/7a8dacab7c1db47261d2c2e2d7f2e138 to your computer and use it in GitHub Desktop.
Save coretravis/7a8dacab7c1db47261d2c2e2d7f2e138 to your computer and use it in GitHub Desktop.
Simple SPA .Net core Routing
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