I'm making a SPA which sits on top of ASP.Net WebAPI. I'm waiting to use HTML5 history rather than #/
for history routing but that poses a problem for deep linking, I need to make sure /
and /foo/bar
all return the same HTML file (and my JS will render the right part of the SPA).
How do I get OWIN/Katana to return the same HTML file for multiple different urls?
To make things simple, while still keeping all the caching goodness etc. from the StaticFiles middleware, I'd just rewrite the request path using an inline middleware, like this
public class Startup
{
public void Configuration(IAppBuilder app)
{
app.Map("/app", spa =>
{
spa.Use((context, next) =>
{
context.Request.Path = new PathString("/index.html");
return next();
});
spa.UseStaticFiles();
});
app.UseWelcomePage();
}
}
This will serve the welcome page on anything but /app/*
, which will always serve index.html instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With