mui / mui-x

MUI X: Build complex and data-rich applications using a growing list of advanced React components, like the Data Grid, Date and Time Pickers, Charts, and more!
https://mui.com/x/
4.07k stars 1.26k forks source link

[docs] Avoid breaking links when doing doc page splits #5172

Open flaviendelangle opened 2 years ago

flaviendelangle commented 2 years ago

The problem

If we do a page split (for instance splitting the columns doc page), Then we change the links used to access the sections

For instance:

It is very hard to do good redirection on the server because most of the time, it impacts the hash part of the URL (for instance #column-spanning) and the server is not aware of it.

Goal

When a user click on an old link created before the split of a page, it should redirect him as close as possible to the content linked to originally.

For instance, if you click on a link to /columns/#controlling-the-pinned-columns, right now it redirects to /columns-definition. It would be nice to at least redirect to /column-pinning (even better to /column-pinning#colntrolling-the-pinned-columns but might be harder).

cherniavskii commented 2 years ago

For instance, if you click on a link to /columns/#controlling-the-pinned-columns, right now it redirects to /columns-definition. It would be nice to at least redirect to /column-pinning (even better to /column-pinning#colntrolling-the-pinned-columns but might be harder).

One way of solving this is client-side redirect. I've tried something like this in _app.js:

React.useEffect(() => {
    if (router.asPath.includes('/x/react-data-grid/group-pivot/#')) {
      // e.g. /x/react-data-grid/group-pivot/#row-grouping => /x/react-data-grid/row-grouping
      const redirectPath = router.asPath.replace('group-pivot/#', '');
      router.replace(redirectPath, redirectPath);
    }
  }, [router]);

It's not perfect: