问题
I don't see an example of using ServiceStack Razor with Multiple SPAs on the internet. The reason for having multiple SPAs in my use case is because my entire site is quite huge and I would like to modularize my site with multiple SPAs. I am aware of the FallbackRoute attribute but it seems to only allow one FallbackRoute based on the documentation? I would like to have, for example, these routes in my app that routes to their respective SPA
- www.mydomain.com/spa1/...
- www.mydomain.com/spa2/...
- www.mydomain.com/spa3/...
Does anyone has an example of this kind of architecture? would be good if its also in the .NET Core architecture
回答1:
Just return the appropriate SPA home page you need for each different Route in the Fallback Route, e.g:
[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);
}
}
来源:https://stackoverflow.com/questions/45388229/servicestack-razor-with-multiple-spas