Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Thomas Ravnholt 12 posts 102 karma points
    Apr 18, 2024 @ 11:08
    Thomas Ravnholt
    0

    Best Practices for Handling Internal Links with Umbraco Delivery API

    Hi everyone,

    I'm currently developing a website using Umbraco's delivery API for the backend and SvelteKit for the frontend. I've run into a challenge regarding the management of internal links within richtext content and would appreciate any insights or suggestions.

    In my setup, I don’t use a root node; instead, all content is organized at the root level and grouped by document types. Consequently, the URLs generated are straightforward, like /page-name. However, I need to map these URLs correctly on the frontend where the structure is different. For example, all articles should be accessible under article/page-name.

    The straightforward approach of typing absolute URLs isn't feasible as it might lead to complications in maintaining the links.

    Does anyone have suggestions on the best way to dynamically resolve these internal links to the correct frontend paths? Perhaps a method to rewrite or intercept these URLs before rendering them on the frontend?

    Thanks in advance for your help!

  • Thomas Ravnholt 12 posts 102 karma points
    Apr 22, 2024 @ 11:53
    Thomas Ravnholt
    0

    Hi again,

    I wanted to share an update on my approach to handling internal links in our SvelteKit frontend that integrates with Umbraco's Delivery API. Since I didn't receive any responses yet, I'm hoping my current solution might spark some discussion or lead to suggestions for improvement.

    Here's what I've implemented so far: In our hooks.server.ts file, I've set up a mechanism to intercept all incoming requests. For requests that do not match any predefined file-based routes, I programmatically query the Umbraco Delivery API using the requested pathname. If the API returns a corresponding page, I then dynamically construct the correct URL to ensure it fits our frontend's routing structure, such as transforming /page-name to /article/page-name.

    This solution seems to work, but I'm curious if there are more efficient or cleaner ways to achieve this. Has anyone dealt with a similar setup or could anyone suggest improvements to this method? Any insights or alternative approaches would be greatly appreciated!

    Thanks for your time!

Please Sign in or register to post replies

Write your reply to:

Draft