简体   繁体   English

反应路由器链接无法正常工作

[英]React-router Link to not working

When using Link to in my component, it renders fine in the browser but when I try to click on the link it doesn't work. 在组件中使用“链接到”时,它在浏览器中呈现良好,但是当我尝试单击链接时,它不起作用。 Nothing happens. 什么都没发生。

Can see everything fine in the inspector and the link goes to the right place but just won't work. 可以在检查器中看到一切正常,链接指向正确的位置,但无法正常工作。

Any ideas what I could be doing wrong? 有什么想法我可能做错了吗?

Code is here: 代码在这里:

import React, { Component } from 'react';
import { Link } from 'react-router';
import classNames from 'classnames';

class myClass extends Component {

render () {
  return (
    <div className="content-about">
      <div className="posts">
        <div className="white-bg"> 
          <div className="main-content no-pad">
          <div className="company-image pt-img-8"></div>
          <div className="center">
            <Link to="/portfolio" className="more">
              <span className="larger-arrow">></span>Back
            </Link></div>
            <div className="main-content pad-50">
              <p>Some content</p>
            </div>
            </div>
        </div>
      </div>
    </div>
  );
 }
}

export default myClass;

Also my Routes are structured as follows: 另外,我的路线的结构如下:

 <Route name="app" path="/" component={App}>
  <Route path="home" component={HomePage} />
  <Route path="portfolio">
      <IndexRoute component={PortfolioPage}/>
      <Route path="xyz" component={XyzPage} />
  </Route>
  <Route path="about" component={AboutPage} />
  <Route path="*" component={error404}/>
 </Route>

Looks like you are missing the root path in each route : 好像您在每条路线中都缺少根路径:

<Route name="app" path="/" component={App}>
  <Route path="/home" component={HomePage} />
  <Route path="/portfolio">
    <IndexRoute component={PortfolioPage}/>
    <Route path="/xyz" component={XyzPage} />
  </Route>
  <Route path="/about" component={AboutPage} />
  <Route path="*" component={error404}/>
</Route>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM