Problem fetching WordPress menu

UPDATE - I have confirmed that the formatting of my source url in frontity.settings.js is creating an issue with how the Wordpress menu is fetched. localhost:8888/folder/ creates an issue where https://somesite.com doesnā€™t. It seems the when I use an location with a subfolder, the urls get /folder as the start of their pathsā€¦but short of altering the urls that get generated in the map function of nav.js, I canā€™t figure out how to address this. Below is my initial postā€¦

I am excited to use Frontity and have really appreciated the videos and documentation! I hope someone in this community can help me figure out how the ā€˜linkā€™ and ā€˜routeā€™ get built/defined, because I think thatā€™s where things are going wrong. Sorry I keep editing, but Iā€™m trying to add info and things Iā€™m tryingā€¦The problem Iā€™m having after fetching my wordpress menu is that the route and link each resolve to ā€˜/newsg/pageā€™ instead of ā€˜/pageā€™ so only the index page at locahost:3000/ loads properly - any other link clicked on in the navigation results in a ā€œ404 - Not Foundā€ error because they each resolve to localhost:3000/newsg/somepage instead of localhost:3000/somepage ā€“ if I delete the /newsg/ part of the url in the address bar, the page loads perfectly.

I donā€™t really understand enough of how things are working to know if the problem is the actually the route. The source url in my frontity.settings.js file is ā€˜http://localhost:8888/newsgā€™ which is the directory of my wordpress site. So that is where I am guessing the /newsg is coming from. But I donā€™t know if somewhere along the line frontity internally does string replacement to have the source url map to localhost:3000/ and Iā€™ve made a mistake somewhere that is interfering with that? (I got thinking along those lines after reading this post Fix/internal links multiple sites by nicholasio Ā· Pull Request #625 Ā· frontity/frontity Ā· GitHub) I also noticed that in the video, Michael is using a subdomain for his project (wp-menu.test/) instead of (wp-menu/test/) and I wonder if making my wp site a subdomain would help this complication? As a shortgap solution, Iā€™ve added the following to my nav.js, which works but imho is a pretty janky solution:

{items.map((item) => {
     **item.url = item.url.replace('/newsg', '');**
     if (!item.child_items) {

Here is a repo of the files: https://github.com/chrisvwlc/frontity.git

And, if I understand correctly, the ā€˜WP REST API urlā€™ is http://localhost:8888/newsg/wp-json/menus/v1/menus/primary.
Thank you for your time and thoughts.

Here is a screenshot showing the error as well as the link and routeā€¦

as well as a page loading if I remove the /newsg

Hi @chrys3136,

Welcome to our Community!!

Have you checked this video?

https://www.youtube.com/watch?v=BMJn0RZ2I9s

It explains how to read the menus defined in your WP installation so they can be used from Frontity

This is the repo with the project explained in the video: frontity-examples/fetch-menu-from-wp at master Ā· frontity-demos/frontity-examples Ā· GitHub

The plugin recommended to share the menus in the REST API: WP-REST-API V2 Menus ā€“ WordPress plugin | WordPress.org

Hope this helps

Hi Juanma and thanks for the response.

Yes, I watched the video and used code from the repo. And I am using the recommended WP REST API V2 Menus plugin.

Iā€™m getting a 404 for every page except the index because all of the urls contain a directory in their paths that they shouldnā€™t.

Can you tell me how/where the urls are constructed/generated?

As I said, Iā€™m using the code in the repo. Within menu-handler.js, there is this block of code:

func: async ({ link, params, state, libraries }) => {
    const { slug } = params;

    // Fetch the menu data from the endpoint
    const response = await api.get({
      endpoint: `/menus/v1/menus/${slug}`,
    });

    // Parse the JSON to get the object
    const menuData = await response.json();

    // Add the menu items to source.data
    const menu = state.source.data[link];

    Object.assign(menu, {
      items: menuData.items,
      isMenu: true,
    });
    console.log("items are: ", menuData.items);
  },

Inside the console.log("items are: ", menuData.items) results, there is a url and a slug for each menu itemā€¦

  [
  {
    ID: 3113,
   ...
    post_title: 'About Us',
   ...
    post_name: 'about-us',
   ...
    guid: 'http://localhost:8888/newsg/?p=3113',
    ...
    object: 'page',
    type: 'post_type',
    type_label: 'Page',
    url: 'http://localhost:8888/newsg/about-the-memorial-2/',
    title: 'About Us',
    ...
    slug: 'about-the-memorial-2',
    child_items: [ [Object], [Object], [Object], [Object] ]
  },

So what is frontity doing with this? I would have assumed that it would replace the source url (http://localhost:8888/newsg) with localhost:3000 and then add on the slugā€¦so for the above item, youā€™d get ā€˜http://localhost:3000/about-the-memorial-2ā€™ But thatā€™s not whatā€™s happening. Somehow the url is http://localhost:3000/sgnew/about-the-memorial-2ā€™ ā€¦ So the question is how is the /sgnew getting in the url strings?

Further, in link.js, there is this line:
<Link link={item.url}>{item.title}</Link>
ā€œitem.urlā€ here is ā€˜http://localhost:8888/newsg/promoting-the-arts/programs/ā€™
So the question again, is how does this become ā€œlocalhost:3000/newsg/promoting-the-arts/programs/ā€ ? Why, if the source url in frontity settings is configured to be ā€œlocalhost:8888/newsgā€ doesnā€™t frontity subtract the source url from the item url and just grab what remains of the url string after? How would I properly change this? Again, the url should just drop the /newsg part to render properly in frontityā€¦ obviously there is someplace where external data gets mapped to frontity data and I feel that must be where Iā€™d be able to fix thisā€¦ I hope this is making sense?

Just doing a string replace in the nav.js (see my intitial post) will work for the navigation but it wonā€™t work for all of the other fetches links and referencesā€¦ Iā€™ll have to deal with this through the siteā€¦ Iā€™ve seen other references to wp subdirectory installs so Iā€™d love to understand why Iā€™m struggling with mine.

Thanks for any insight you can offer!