Is there a good way to associate with a named anchor in React.js?

I have a single page table of contents for the React.js Single Pages (SPA) application page. Each of the elements in the table of contents is a link to a section on another page.

eg.

<ul>
    <li><a href='/newpage#atarget'>A Target</a></li>
    <li><a href='/newpage#btarget'>B Target</a></li>
    ...
</ul>

which will link to a new page containing something like

<a name='atarget' />
<h2>A Target</h2>
    ...

<a name='btarget' />
<h2>bTarget</h2>
    ...

What I find is that even when manually viewing / newpage / atarget, I donโ€™t get to the right place. I assume this is because React.js displays the page after loading.

I would like

  • response-router to be able to use links in the table of contents to avoid updating
  • Named goals work either through a link or when manually pasting into a URL string

- 2. , , . 1.

+4

Source: https://habr.com/ru/post/1611826/


All Articles