如何在 Meteor 中集成 React Router?

How to integrate React Router in Meteor?

我正在尝试在 Meteor 项目中使用 React Router 集成路由。我遵循了 Meteor React 文档,但不知何故它不起作用。尝试过使用“路由器”而不是“BrowserRouter”,但没有成功。对此有何建议。

imports/startup/client/routes.js

import { BrowserRouter, Route, Switch } from "react-router-dom";

import App, City , NotFound from "respective-modules";
 
export const renderRoutes = () => {
  <BrowserRouter>
    <div>
      <Switch>
        <Route exact path="/" component={App} />
        <Route exact path="/city" component={City} />
        <Route component={NotFound} />
      </Switch>
    </div>
  </BrowserRouter>;

client/main.html

<body>
  <div id="react-target"></div>
</body>

client/main.jsx

import { renderRoutes } from "/imports/startup/client/routes.js";

Meteor.startup(() => {
  render(renderRoutes(), document.getElementById("react-target"));
});

但是出现了一个空白页。

如果您显示的代码是正确的(即从您的内容中准确复制运行),那么您只是多了一个大括号:

export const renderRoutes = () => {
  <BrowserRouter>

需要是:

export const renderRoutes = () => 
  <BrowserRouter>

export const renderRoutes = () => {
  return <BrowserRouter>