带有多个SPA的ServiceStack Razor [英] ServiceStack Razor with Multiple SPAs

查看:71
本文介绍了带有多个SPA的ServiceStack Razor的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我没有看到在Internet上将ServiceStack Razor与多个SPA一起使用的示例.在我的用例中拥有多个SPA的原因是因为我的整个站点都非常庞大,并且我想用多个SPA来模块化我的站点.我知道FallbackRoute属性,但是根据文档,它似乎只允许一个FallbackRoute?例如,我想在我的应用程序中使用这些路由以路由到各自的SPA

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/...

有人有这种架构的例子吗?如果它也适用于.NET Core体系结构,那将是很好的选择

Does anyone has an example of this kind of architecture? would be good if its also in the .NET Core architecture

推荐答案

仅返回后备路由中每个不同路由所需的相应SPA主页,例如:

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);
    }
}

这篇关于带有多个SPA的ServiceStack Razor的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆