首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >React-router-dom链接不重定向

React-router-dom链接不重定向
EN

Stack Overflow用户
提问于 2020-01-17 03:15:40
回答 1查看 21关注 0票数 0

我正试着在blocks...but中加入一些链接,这对我不起作用。我想这么做。

链接标记未重定向...

代码语言:javascript
复制
const Relacionados = props => {
    const {items} = props;
    const links = items.map((item, index) =>
        <li key={index}><Link to={'/noticia-' + item.id}>{item.titulo}</Link></li>
    )
    return (
        <div className={'related bg-secondary'}>
            {items.length === 0 || <h4 className="text-white ml-3 intro">También podría interesarte...</h4>}
            <ul>
                {links}
            </ul>
        </div>
    )
}

未显示的部分如下:

代码语言:javascript
复制
 <BrowserRouter>
     {entity === null || <NavbarErma entity={entity}/>}
     <Route exact path="/" component={HomePage2}/>
     <Route path="/noticia-:id" component={LeerNoticia}/>
 </BrowserRouter>
EN

回答 1

Stack Overflow用户

发布于 2020-01-17 03:43:06

我发现了我自己。这解决了我的麻烦!

代码语言:javascript
复制
 componentWillReceiveProps(nextProps) {
        if(this.props.match.params.id !== nextProps.match.params.id) {
            apiGET('/noticias/' + nextProps.match.params.id).then(items => {
                this.updateState(items.data, 'noticia')
            })
        }
    }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59776386

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档