Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(Docs): Routes for internal relative links are root-relative and therefore broken for in-app docs #5917

Closed
tonyketcham opened this issue May 27, 2021 · 4 comments

Comments

@tonyketcham
Copy link

1) The issue and what you expected to happen

Clicking on links of internal references while using the in-app documentation gives the user a route error instead of taking them to the intended page.

2) Exact steps to reproduce this issue

Clicking a relative link in the in-app documentation as an admin user:
Screen Shot 2021-05-27 at 12 31 09 PM

Results in this error:
https://<example-domain>/concepts/items/

{
  "errors": [
    {
      "message": "Route /concepts/items/ doesn't exist.",
      "extensions": {
        "code": "ROUTE_NOT_FOUND"
      }
    }
  ]
}

For the in-app documentation, the above route should resolve to:
https://<example-domain>/admin/docs/concepts/items/

3) Your environment:

Directus v9.0.0-rc.69
Deployment: npx
Version 1.18.78 Chromium: 87.0.4280.141 (Official Build)
@tonyketcham
Copy link
Author

A potential solution could be adding a custom permalink rendering function in the markdown.anchor config of the docs' VuePress instance. That function could reference a new environment variable DOCS_PATH which, if defined, prefixes internal relative links with the declared path.

Then the in-app environment would have:
DOCS_PATH=/admin/docs

And docs.directus.io could fall back to the default of prefixing nothing.

@tonyketcham tonyketcham changed the title (Docs): Routes in anchor tags are root-relative and therefore broken for in-app docs (Docs): Routes for internal relative links are root-relative and therefore broken for in-app docs May 27, 2021
@rijkvanzanten
Copy link
Member

Currently, the docs module should handle clicks and use vue-router to navigate when clicking on an anchor:

function onClick(event: MouseEvent) {
if (
event.target &&
(event.target as HTMLElement).tagName.toLowerCase() === 'a' &&
(event.target as HTMLAnchorElement).href
) {
const link = (event.target as HTMLAnchorElement).getAttribute('href')!;
if (link.startsWith('http') || link.startsWith('#')) return;
event.preventDefault();
const parts = link.split('#');
parts[0] = parts[0].endsWith('/') ? parts[0].slice(0, -1) : parts[0];
router.push({
path: `/docs${parts[0]}`,
hash: parts[1],
});
}
}

Not sure why that doesn't seem to work on your end 🤔

@rijkvanzanten
Copy link
Member

markdown.anchor is markdown-it-anchor is only for header links, so won't really help here

@rijkvanzanten
Copy link
Member

Thank you for taking the time to submit this! Unfortunately, our team was not been able to reproduce it based on the information provided. Therefore, we will close this ticket for now, but will happily re-open it if new details are provided that allow us to reliably replicate the problem.

As a reminder:

  • Provide as much detail as possible in the issue description
  • Video screen captures and clear steps are very helpful
  • A full SQL dump is the fastest way for us to test/resolve (can be sent privately)
  • Make sure you are on the latest version of Directus
  • Did you try turning it off and on again?

This is an automated response.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 3, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants