2.0.12 • Published 4 months ago

@voicenter-team/umbraco-headless v2.0.12

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

umbraco-headless

Nuxt module that helps you to easily load your Umbraco data directly into your great Nuxt project.

Setup:

  1. Install dependency by running npm i @voicenter-team/umbraco-headless or yarn add @voicenter-team/umbraco-headless
  2. Configure your nuxt project by adding the following:
// nuxt.config.js
{
    modules: [
        // ...
        '@voicenter-team/umbraco-headless'
    ]
}

Options:

In order to configure the module - create umbraco-headless.config.js file in the root of your Nuxt project. The following options can be specified while setting the module:

OptionDescriptionDefaultRequired
getUmbracoDataAPIAn URI where plugin will do a POST requests in order to fetch Umbraco Data-true
generateUmbracoDataAPIAn URI where plugin will do a POST requests in order to fetch sitemap.xml robots.txt, umbracodata.json to generate files-true
siteThe name of the website-true
trailingSlashRedirectThe value makes a 301 redirection to a non trailing slash URLfalsefalse
prefixThe value that if passed will generate routes with that prefix, example: if prefix "es", then route as "/about-us/contacts" will be "/es/about-us/contacts"''false
redirects--false
redirects.enableIf to enable 301 redirectsfalse-
redirects.redirectFolderNameName of the Umbraco Data content type where to find redirects (plugin will check children's oldUrl/newUrl key pairs)redirectFolder-
redirects.rootChildrenUmbracoPathPath of the children contentSiteData.children-
redirects.enableInDevelopmentWhenever to do redirects in development modefalse-

Make sure you have all the created components in your pages folder. But if you don't have all the needed components - the plugin will setup the index.vue component for all the missing components routes.

:warning: Be aware that this module will automatically setup the Vuex storage for your Nuxt project.

Example:

// umbraco-headless.config.js
export default {
  getUmbracoDataAPI: 'https://nuxt-umbraco-api.voicenter-ltd.workers.dev/',
  generateUmbracoDataAPI: 'http://localhost:3030',
  site: 'voice_he_prod',
  redirects: {
    enable: true,
    redirectFolderName: 'redirectFolder',
    rootChildrenUmbracoPath: 'SiteData.children',
    enableInDevelopment: true
  },
  prefetch: [
    {
      fetch: {
        type: 'contentType',
        pattern: 'websiteMainNavigation'
      },
      globalKey: 'websiteMainNavigation'
    }
  ]
}

Usage

Just add the following to your pages components:

async asyncData (context) {
    const data = await context.$Umbraco.get(context, {
        fetch: {
            type: 'path',
            pattern: context.route.meta[0].Jpath
        },
        apiOnly: true || false,                 // If apiOnly true your page will be fetched from api
                                                // If your Component is available in Vue store you set apiOnly false and your component
                                                // will be fetched from your Vuex store
    }) || {}
    return data;
}

If you want to fetch your Page by contentType:

async asyncData (context) {
    const data = await context.$Umbraco.get(context, {
        fetch: {
            type: 'contentType',
            pattern: '[your content type value]'
        },
        apiOnly: true || false                 // If apiOnly true your page will be fetched from api
                                               // If your Component is available in Vue store you set apiOnly false and your component
                                               // will be fetched from your Vuex store
    }) || {}
    return data;
}
2.0.12

4 months ago

2.0.9

4 months ago

2.0.10

4 months ago

2.0.8

11 months ago

2.0.7

11 months ago

2.0.6

11 months ago

2.0.5

11 months ago

2.0.4

11 months ago