Custom handler won't work as expected

  • Description of your issue
    • I am trying to write a custom handler to handle specific routes such that “testsite.com/en/about-us” where “en” is the language code and “about-us” is the slug. If this path is given, English version of “About Us” page will be loaded. I already checked some community answers but I could not find the issue for my code. On the other hand, “/blog” and “/” paths are working properly. If I add another handler, it does not work as expected.

actions in index.js

  actions: {
    theme: {
      init: ({ libraries }) => {
        libraries.source.handlers = libraries.source.handlers.filter(
          (h) => !["post archive"].includes(h.name)
        );

        libraries.source.handlers.push({
          name: "page with lang",
          priority: 7,
          pattern: "/:lang/:slug/",
          func: async (options) => {
            await postTypeHandler({
              endpoints: ["pages"],
            })({
              ...options,
              params: { ...options.params },
            });
          },
        });

        libraries.source.handlers.push({
          name: "page",
          priority: 9,
          pattern: "/",
          func: async (options) => {
            await postTypeHandler({ endpoints: ["pages"] })({
              ...options,
              params: { ...options.params, slug: "/" },
            });
          },
        });

        libraries.source.handlers.push({
          name: "post archive",
          priority: 8,
          pattern: "/blog/",
          func: async (options) => {
            await postTypeArchiveHandler({
              type: "post",
              endpoint: "posts",
            })({
              ...options,
            });
          },
        });
      },
      openMobileMenu: ({ state }) => {
        state.theme.isMobileMenuOpen = true;
      },
      closeMobileMenu: ({ state }) => {
        state.theme.isMobileMenuOpen = false;
      },
      toggleMobileMenu: ({ state }) => {
        state.theme.isMobileMenuOpen = !state.theme.isMobileMenuOpen;
      },
      setLanguage: ({ state }) => value => {
        state.theme.language = value;
      }
    },
  },
  libraries: {
    html2react: {
      /**
       * Add a processor to `html2react` so it processes the `<img>` tags
       * inside the content HTML. You can add your own processors too
       */
      processors: [image, LinkHandler],
    },
  },

Hi @rawsly

Welcome to the Frontity community.

What are your functions postTypeHandler and postTypeArchiveHandler doing. Could you provide a link to a repo so we can see your code and clone the project so we can run it if necessary, thanks. If your API is publicly available so we can see the data being fetched and run the project with your data that would be even more awesome.

Please see here for the information that you can provide which will best enable us to help you.