<bdo id='dAe4z'></bdo><ul id='dAe4z'></ul>
  1. <small id='dAe4z'></small><noframes id='dAe4z'>

  2. <legend id='dAe4z'><style id='dAe4z'><dir id='dAe4z'><q id='dAe4z'></q></dir></style></legend>
  3. <tfoot id='dAe4z'></tfoot>

      <i id='dAe4z'><tr id='dAe4z'><dt id='dAe4z'><q id='dAe4z'><span id='dAe4z'><b id='dAe4z'><form id='dAe4z'><ins id='dAe4z'></ins><ul id='dAe4z'></ul><sub id='dAe4z'></sub></form><legend id='dAe4z'></legend><bdo id='dAe4z'><pre id='dAe4z'><center id='dAe4z'></center></pre></bdo></b><th id='dAe4z'></th></span></q></dt></tr></i><div id='dAe4z'><tfoot id='dAe4z'></tfoot><dl id='dAe4z'><fieldset id='dAe4z'></fieldset></dl></div>

      路由到 React 中其他组件的特定部分

      时间:2023-09-07

          <bdo id='jyuOi'></bdo><ul id='jyuOi'></ul>
          <i id='jyuOi'><tr id='jyuOi'><dt id='jyuOi'><q id='jyuOi'><span id='jyuOi'><b id='jyuOi'><form id='jyuOi'><ins id='jyuOi'></ins><ul id='jyuOi'></ul><sub id='jyuOi'></sub></form><legend id='jyuOi'></legend><bdo id='jyuOi'><pre id='jyuOi'><center id='jyuOi'></center></pre></bdo></b><th id='jyuOi'></th></span></q></dt></tr></i><div id='jyuOi'><tfoot id='jyuOi'></tfoot><dl id='jyuOi'><fieldset id='jyuOi'></fieldset></dl></div>

            <tfoot id='jyuOi'></tfoot>
          • <legend id='jyuOi'><style id='jyuOi'><dir id='jyuOi'><q id='jyuOi'></q></dir></style></legend>

              <small id='jyuOi'></small><noframes id='jyuOi'>

                <tbody id='jyuOi'></tbody>

              1. 本文介绍了路由到 React 中其他组件的特定部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我在路由到 React 中另一个功能组件的特定部分时遇到问题.我已经在 Main 组件中声明了 Route 并在我想要重定向的地方周围链接了......它看起来像这样......主函数获取:

                I have a problem with routing to a specific part of another functional component in React. I have declared Route in Main component and Link around the place where I want to redirect from... it looks like this... The main function gets:

                <Switch>
                    <Route exact path='/news/:eyof' component={News} />
                    <Route exact path='/news/:svetsko' component={News} />
                    <Route exact path='/news' component={News} />
                </Switch>
                

                而我在其他功能组件中定义:

                And I defined in other functional component:

                <div className="card">
                  <Link to="/news/:svetsko">
                    <div className="card-header">
                      <h3>Artistic gymnastics world championship</h3>
                     </div>
                   </Link>
                </div>
                

                因此,通过单击此链接,我需要重定向到新闻页面类svetsko",以便我可以阅读该新闻...所有新闻都在同一页面的容器中....

                So by clicking on this link, I need to get redirected to News page class "svetsko" so I can read about that news... All news are in containers in same page....

                推荐答案

                在你的组件中尝试这样的事情:

                Try something like this in your component:

                let { scrollToSection } = useParams();
                svetskoRef = React.createRef();
                

                useParams() 允许您访问 :svetsko.当组件加载时,您可以使用 scrollToSection 在页面的不同部分之间导航.scrollRef 用于访问要滚动到的 DOM 元素.

                useParams() allows you to access :svetsko. When the component loads, you can use scrollToSection to navigate between different parts of the page. The scrollRef is used to access the DOM element you want to scroll to.

                window.scrollTo(0,scrollRef.offsetTop)
                

                标记看起来像这样:

                <div className="card" ref="svetskoRef">
                  <Link to="/news/:svetsko">
                    <div className="card-header">
                      <h3>Artistic gymnastics world championship</h3>
                     </div>
                   </Link>
                </div>
                

                这篇关于路由到 React 中其他组件的特定部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:GlideJS - 使用带有 React 组件的幻灯片时的奇怪行为 下一篇:如何转到 Chrome 开发者工具中的特定文件?

                相关文章

                  <tfoot id='S6tWn'></tfoot>
                  • <bdo id='S6tWn'></bdo><ul id='S6tWn'></ul>

                1. <legend id='S6tWn'><style id='S6tWn'><dir id='S6tWn'><q id='S6tWn'></q></dir></style></legend>

                  <small id='S6tWn'></small><noframes id='S6tWn'>

                  <i id='S6tWn'><tr id='S6tWn'><dt id='S6tWn'><q id='S6tWn'><span id='S6tWn'><b id='S6tWn'><form id='S6tWn'><ins id='S6tWn'></ins><ul id='S6tWn'></ul><sub id='S6tWn'></sub></form><legend id='S6tWn'></legend><bdo id='S6tWn'><pre id='S6tWn'><center id='S6tWn'></center></pre></bdo></b><th id='S6tWn'></th></span></q></dt></tr></i><div id='S6tWn'><tfoot id='S6tWn'></tfoot><dl id='S6tWn'><fieldset id='S6tWn'></fieldset></dl></div>