How to use react router (createBrowserHistory) on Microsoft IIS to make routing working?

后端 未结 6 1696
情深已故
情深已故 2020-12-03 08:54

I am using react-router (createBrowserHistory) for my react app.

Below is my code of

var ReactDOM = require(\'react-dom\') ;

var ReactRouter = req         


        
6条回答
  •  广开言路
    2020-12-03 08:56

    Another option is using an application on top of IIS to ensure you've got other features that might come in handy, like the ASP.NET framework with MVC on top of it. You could have a route there that simply catches all requests that aren't specifically mapped (like /api, /content) and route these to the html in such a way that your React app can handle it. The benefits over pure IIS really depend on your circumstance.

    The following is my route configuration for ASP.NET Core, to give you an example:

    app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller}/{action}/{id?}",
                    defaults: new {controller = "Home", action = "Index"},
                    constraints: new { controller = new NotEqualConstraint("api")});
    
                routes.MapRoute("api", "api/{controller}/{action}/{id?}");
                routes.MapRoute("React failover", "app/{*uri}", new {controller = "App", action = "Index"},
                    new {controller = new NotEqualConstraint("api")});
    
            });
    

提交回复
热议问题