【问题标题】:react router v4 "/" exact path not working with cordova反应路由器v4“/”确切路径不适用于cordova
【发布时间】:2017-05-13 17:44:57
【问题描述】:

尝试在 IntelXDK 中使用 cordova 插件执行此操作,但它不显示任何内容

const app = document.getElementById('app');

const Index = () => (
    <Router>
      <div>
        <Switch>
            <Route exact path="/" component={Layout}/>
            <Route path="/about" component={First}/>
            <Route path="/topics" component={Second}/>
        </Switch>
      </div>
    </Router>

);

const Layout = () => (
    <div>
        <h1>layout</h1>
        <ul>
            <li><Link to="/">Home</Link></li>
            <li><Link to="/about">About</Link></li>
            <li><Link to="/topics">Topics</Link></li>
        </ul>
    </div>
);

const First = () => (
    <div>
        <h1>first</h1>
    </div>
);

const Second = () => (
    <div>
        <h1>second</h1>
    </div>
);


ReactDOM.render(<Index/>, app);

当我删除 exact 字而不使用 &lt;Switch&gt; 标记时,它可以工作,但会呈现 2 个组件(布局和第一个或布局和第二个)。

我只想渲染 1 个组件,有人可以帮我解决这个问题吗?

【问题讨论】:

    标签: android cordova reactjs react-router intel-xdk


    【解决方案1】:

    您可以尝试删除确切的属性并将 / 路由放在 3 条路由的末尾。如果不是其他的,它只会渲染。但如果它是其他东西,它也会呈现,所以我不确定你是否想避免这种情况。

    最好的问候

    【讨论】:

      猜你喜欢
      • 2019-08-03
      • 2020-08-22
      • 2018-12-31
      • 2019-01-28
      • 2018-02-06
      • 2020-11-01
      • 1970-01-01
      • 2017-12-06
      • 2017-12-16
      相关资源
      最近更新 更多