【问题标题】:React router 4 server-side rendering using IIS, not express使用 IIS 的 React router 4 服务器端渲染,而不是 express
【发布时间】:2017-10-09 22:27:33
【问题描述】:

我正在尝试使用 react-router v4 进行服务器端渲染。那里的所有文档都使用快速服务器,但我使用的是 windows iis。我可以让它在仅客户端渲染上工作,但是当我尝试渲染服务器端时,我得到错误“哈希历史需要一个 dom”。有什么建议吗?

我确定所有内容都已正确导入,因此我将从以下代码中删除导入。

代码如下:

const createStoreWithMiddleware = applyMiddleware(ReduxPromise)(createStore);


const someText = <p><strong>Some JSX component</strong><br/>Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.</p>
const simpleContent = (props) => { console.log(props); return (<SimpleContent placeholders={{leftColumn: <Counter data={{title: 'Nested counter'}}/>, rightColumn: <Timer data={{title: 'Nested counter'}}/>}}/>) }

const RouteHub = (props) => {
    return (
        <Provider store={createStoreWithMiddleware(reducers)}>
           <HashRouter>
            <div>
              <h1>Title</h1>
                <ul>
                  <li><Link to="/">Home</Link></li>
                  <li><Link to="/simple">Simple Content</Link></li>
                </ul>
              <Switch>
                <Route exact name="index" path='/' component={simpleContent}/>
                <Route name="simple" path='/simple' component={SimpleContent}/>
              </Switch>
            </div>
          </HashRouter>
        </Provider>
    )
}

export default RouteHub;

【问题讨论】:

标签: reactjs react-redux react-router-redux server-side-rendering react-router-v4


【解决方案1】:

使用 StaticRouter 而不是 HashRouter 解决了错误。

谢谢egig!

【讨论】:

    猜你喜欢
    • 2015-08-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-06
    • 2016-03-26
    • 2016-11-17
    • 1970-01-01
    • 2016-05-09
    相关资源
    最近更新 更多