NancyFX Catch All route

后端 未结 4 1149
迷失自我
迷失自我 2021-02-19 02:38

Does NancyFX supports ASP.NET MVC like \'Catch All\' route? I need one, that basically match every URL. This is very handy for building up Single Page applications.

Is t

4条回答
  •  悲哀的现实
    2021-02-19 03:17

    Answer provided by @synhershko does not work for me. It does not handle /users/2 or any other route containing more segements.

    Below code works on my machine ;) :

    public class IndexModule : NancyModule
    {
        dynamic IndexPage() { return View["Index"]; }
    
        public IndexModule()
        {
            Get["/"] = _ => { return IndexPage(); };
            Get["/(.*)"] = _ => { return IndexPage(); };
            Get["/(.*)/(.*)"] = _ => { return IndexPage(); };
            Get["/(.*)/(.*)/(.*)"] = _ => { return IndexPage(); };
        }
    }
    

    My solution is not perfect, cause it does not match everything. I repeated as many '/(.*)' as in my longest Angular route.

提交回复
热议问题