<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 中其他组件的特定部分

      Routing to specific part of other component in React(路由到 React 中其他组件的特定部分)

          <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 中其他组件的特定部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                Pause youtube video, youtube api(暂停 youtube 视频,youtube api)
                Youtube iframe api not triggering onYouTubeIframeAPIReady(Youtube iframe api 未触发 onYouTubeIframeAPIReady)
                How can I stop a video with Javascript in Youtube?(如何在 Youtube 中停止使用 Javascript 的视频?)
                How to call Greasemonkey#39;s GM_ functions from code that must run in the target page scope?(如何从必须在目标页面范围内运行的代码中调用 Greasemonkey 的 GM_ 函数?)
                How do you mute an embedded Youtube player?(如何使嵌入式 Youtube 播放器静音?)
                How to get number of video views with YouTube API?(如何使用 YouTube API 获取视频观看次数?)
                  <tfoot id='S6tWn'></tfoot>
                  • <bdo id='S6tWn'></bdo><ul id='S6tWn'></ul>

                      <tbody id='S6tWn'></tbody>
                      • <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>