如何在 Microsoft IIS 上使用 react router (createBrowserHistory) 使路由正常工作? [英] How to use react router (createBrowserHistory) on Microsoft IIS to make routing working?

查看:26
本文介绍了如何在 Microsoft IIS 上使用 react router (createBrowserHistory) 使路由正常工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为我的 React 应用程序使用 react-router (createBrowserHistory).

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

下面是我的代码

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

var ReactRouter = require('react-router');
var Router = ReactRouter.Router;
var Route = ReactRouter.Route;
var Link = ReactRouter.Link;
var browserHistory = require('react-router');
var createBrowserHistory = require('history/lib/createBrowserHistory');

var CL = require('./page1/1.jsx');
var Validation = require('./page3/3.jsx');
var Infos = require('./page4/4.jsx');
var Confirm = require('./page7/7.jsx');
var Upload = require('./page8/8.jsx');

module.exports = (

  <Router history={new createBrowserHistory()}> 
    <Route path='/' component={CL}></Route>                                                                                                                                     
    <Route path='/validation' component={Validation}></Route>                                                                                                                                     
    <Route path='/infos' component={Infos}></Route>                                                                                                                                     
    <Route path='/confirm' component={Confirm}></Route>                                                                                                                                     
    <Route path='/upload' component={Upload}></Route>                                                                                                                                     
  </Router>
)

Wen 在本地运行 IIS,我在浏览器上转到 localhost,我可以获得CL"组件并显示在页面上,但是,如果我转到/validation,我会得到

Wen run IIS on local, I go to localhost on browser, I can get "CL" component and show on page, however, if I go to /validation, I will get

Failed to load resource: the server respond with status of 404 (Not Found)

有人知道需要向 IIS 或我的 js 代码添加什么才能使此路由正常工作吗?

Anyone know what need to add to IIS or my js code to make this routing work?

推荐答案

我认为你在谈论 react-router 或类似的东西iis 7 上的以下配置对我有用

I think you are talking about react-router or similar stuff below configuration on iis 7 works for me

<rules>
     <rule name="Rewrite Text Requests" stopProcessing="true">
         <match url=".*" />
             <conditions>
                        <add input="{HTTP_METHOD}" pattern="^GET$" />
                        <add input="{HTTP_ACCEPT}" pattern="^text/html" />
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
             </conditions>
             <action type="Rewrite" url="/index.html" />
     </rule>
</rules>

这篇关于如何在 Microsoft IIS 上使用 react router (createBrowserHistory) 使路由正常工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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