reactjs React:如果url相似,路由器不刷新页面

5jvtdoz2  于 2023-02-22  发布在  React
关注(0)|答案(1)|浏览(154)

我有这个应用程序:

function App() {
  
const reload = () => {
  console.log()
}

  return (
    <div className="App">
      <Router>
        <div>
          <Link to="/table/metadata/" onClick={reload}>
            
            <button class="button" >
                <span>
                  Metadata
                </span>
            </button>
          </Link>
          <Link to="/table/spot/">
            <button class="button">
                <span>
                  SPOT
                </span>
            </button>
          </Link>
          <Link to="/table/activity/">
            <button class="button">
                <span>
                  Activity
                </span>
            </button>
          </Link>
          <Link to="/table/users/">
            <button class="button">
                <span>
                  Users
                </span>
            </button>
          </Link>
        </div>
        <Routes>

          <Route path="/table/:name/" element={<SortingTable/>}></Route>
          <Route path="" exact element={<BasicTable/>}></Route>
        </Routes>
      </Router>
    </div>
  );
}

如果我从localhost转到localhost/table/any_table,页面会显示正确的表,但如果我尝试从任何表转到另一个表,例如从localhost/table/activity转到localhost/table/metadata,则页面会显示活动表,而url会更改为localhost/table/metadata

zf9nrax1

zf9nrax11#

变更:

const reload = () => {
  console.log()
}

收件人:

const reload = () => {
  console.log()
  navigate('table/metadata/')
}

相关问题