只需为备用路由中的每个不同路由返回您需要的相应 SPA 主页,例如:
[FallbackRoute("/{PathInfo*}")]
public class FallbackForClientRoutes
{
public string PathInfo { get; set; }
}
public class MyServices : Service
{
//Return SPA index.html for unmatched requests so routing is handled on client
public object Any(FallbackForClientRoutes request)
{
if (request.PathInfo.StartsWith("/spa1"))
return new HttpResult(VirtualFileSources.GetFile("spa1/index.html"));
if (request.PathInfo.StartsWith("/spa2"))
return new HttpResult(VirtualFileSources.GetFile("spa2/index.html"));
if (request.PathInfo.StartsWith("/spa3"))
return new HttpResult(VirtualFileSources.GetFile("spa3/index.html"));
throw new NotSupportedException("Unknown Route: " + request.PathInfo);
}
}