具有多个SPA的ServiceStack Razor

时间:2017-07-29 10:35:48

标签: razor asp.net-core servicestack single-page-application servicestack-razor

我没有看到在互联网上使用ServiceStack Razor和多个SPA的示例。在我的用例中有多个SPA的原因是因为我的整个站点非常庞大,我想用多个SPA模块化我的站点。我知道FallbackRoute属性,但它似乎只允许一个基于文档的FallbackRoute?例如,我希望在我的应用程序中有这些路线可以路由到各自的SPA

  • www.mydomain.com/spa1 /...
  • www.mydomain.com/spa2 /...
  • www.mydomain.com/spa3 /...

有没有人有这种架构的例子?如果它也在.NET核心架构中会很好

1 个答案:

答案 0 :(得分:0)

只需返回后备路线中每条不同路线所需的相应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);
    }
}