Nuxt with SM Routes

Hello @arcaneshawn,

I have discussed this with our dedicated developer. Here are some bits to help you on that one:

Mapping URLs:
If you are using the apiOptions.routes feature that is not able to do that kind of programmatic parsing, unfortunately. I'd recommend using a link resolver here, something like that:

// linkResolver.js
module.exports = doc => {
  const [site, uid] = doc.uid.split("--");

  switch(doc.type) {
    case "page":
      return `/${site}/${uid}`;

    default:
      return "/";
  };
};

Querying the right UID:
Here I'd suggest leveraging Vue router params to resolve the UID and query the right document:

// ~/pages/mysite1/_uid.vue
export default {
  async asyncData({ route }) {
    const site = route.path.split("/").filter(i => !!i)[0];
    const resolvedUid = `${site}--${route.params.uid}`; // e.g. "mysite1--contact-us"
    /* ... */
  }
};

Give this a try and let me know.

Thanks,

Priyanka

1 Like