ServiceStack Razor with Multiple SPAs

不羁的心 提交于 2020-01-05 06:26:27

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!