【问题标题】:How can I use React-route correctly?如何正确使用 React-route?
【发布时间】:2018-12-16 20:13:51
【问题描述】:

这种情况:我的主页有index.html。我不使用 React。但是在主页上有一个我使用 React 的游戏页面上的链接。

我需要在游戏页面上创建应用程序,但 webpack(我认为)只能在 index.html. 上渲染应用程序我在游戏页面上有渲染容器。但反应忽略它。另一方面,当我在主页上为 rander 创建容器时,一切正常。

代码和平:

import React from 'react';
import ReactDOM from 'react-dom';

import ElectronApp from './components/ElectronApp';

import {
  HashRouter,
  Route
} from 'react-router-dom'


ReactDOM.render(
  <HashRouter>
    <Route path="/electron-game.html" component={ElectronApp} />
  </HashRouter>,
  document.getElementById('root')
)

我可以做些什么来解决我的问题,我不知道我需要使用路由器。

【问题讨论】:

标签: javascript reactjs


【解决方案1】:

我知道你说你在主页中不需要 React,但它可能更容易(如果你真的想像这样使用 React 路由器),将链接作为 React 组件处理,然后让它路由到 Electron 应用程序。

这里有一个使用 React Router 的相对清晰的例子: https://reacttraining.com/react-router/web/example/basic

我建议看看该页面上的情况如何。

另外,我在您的示例中注意到一件事 - 您不需要“/electron-game.html”中的“html”。它没有获得实际的 html 资源。

【讨论】:

    猜你喜欢
    • 2018-12-26
    • 2019-12-30
    • 2016-09-28
    • 2018-03-25
    • 2020-05-06
    • 1970-01-01
    • 1970-01-01
    • 2019-10-26
    • 2021-10-15
    相关资源
    最近更新 更多