【问题标题】:react-router 2.8 Link to add path instead of replacereact-router 2.8链接添加路径而不是替换
【发布时间】:2017-03-28 00:28:53
【问题描述】:

我正在尝试使用 react-router 和 redux 进行分页。 为了简化情况,我删除了分页器,只留下了 News 组件。 我也有同样的问题。当我按下按钮 Route 添加到路径。路径看起来像'http://localhost:3000/news/page/news/page/news/page/4'。

import React, { Component } from 'react'
import { Link } from 'react-router'
  
export default class News extends Component {
  render() {
    let nextPage = + (this.props.params.page || 1);
    return(
    <div>
    <h1>I am on {nextPage}</h1>
    <ul>
      <li><Link to='news/page/2'>Page2</Link></li>
      <li><Link to='news/page/3'>Page3</Link></li>
      <li><Link to='news/page/4'>Page4</Link></li>
    </ul>
    </div>
  )
    }}

export const routes = (
  <div>
    <Route path='/' component={App}>
      <IndexRoute component={Home}/>
      {/*}<IndexRedirect to='list' />*/}
      <Route path='/news(/page/:page)' component={News}/>    
      <Route path='/admin' component={Admin}  onEnter={Admin.onEnter}/>
      <Route path='products' component={Products}/>
      <Route path='contacts' component={Contacts}/>
      <Route path='about' component={About} />
      <Route path='login' component={LoginPage} />
      <Route path='orders' component= {Orders}/>
      <Route path='signup' component={SignupPage}/>
      <Route path='validateEmail' component= {requireIdentification(ValidateEmail)}/>
      <Route path='/verifyEmail/:token' component={CheckEmail}/>
    </Route>
    <Route path='*' component={NotFound} />
  </div>
)

【问题讨论】:

    标签: hyperlink pagination react-router


    【解决方案1】:

    决定是

    &lt;li&gt;&lt;Link to='/news/page/2'&gt;Page2&lt;/Link&gt;&lt;/li&gt;

    而不是

    &lt;li&gt;&lt;Link to='news/page/2'&gt;Page2&lt;/Link&gt;&lt;/li&gt;

    【讨论】:

      猜你喜欢
      • 2016-11-23
      • 1970-01-01
      • 2021-11-02
      • 2020-08-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-08
      相关资源
      最近更新 更多