Wrong routes with /_nuxt/ prefix in sitemap

AlexBa
5
AlexBa
commented 7 months ago

Version
v1.0.0

Reproduction link
https://alexanderbarton.de/sitemap.xml

Steps to reproduce
Just generate the sitemap with the config. :)

What is expected ?
Routes in sitemap without the /_nuxt/ prefix

What is actually happening?
Routes in sitemap with /_nuxt/ prefix

Additional comments?
This is my nuxt.config.js:

const pkg = require('./package');
const dotenv = require('dotenv');

dotenv.config();

module.exports = {
mode: 'universal',

/*
** Headers of the page
*/
head: {
title: pkg.name,
meta: [
{ charset: 'utf-8' },
{ name: 'viewport', content: 'width=device-width, initial-scale=1' },
{ hid: 'description', name: 'description', content: pkg.description }
],
link: [
{ rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' },
]
},

/*
** Customize the progress-bar color
*/
loading: false,

/*
** Global CSS
*/
css: [
'~assets/scss/style.scss',
],

/*
** Plugins to load before mounting the App
*/
plugins: [
{src: '~plugins/bootstrap-native', ssr: false},
{src: '~plugins/tiny-slider', ssr: false}
],

/*
** Nuxt.js modules
*/
modules: [
'@nuxtjs/dotenv',
'@nuxtjs/axios',
'@nuxtjs/redirect-module',
['@nuxtjs/google-tag-manager', {
id: process.env.GTMCONTAINERID
}],
['nuxt-i18n', {
strategy: 'prefixexceptdefault',
defaultLocale: 'de',
lazy: true,
langDir: 'translations/',
locales: [
{
code: 'de',
file: 'de.json'
}
],
}],
'@nuxtjs/sitemap'
],

axios: {
// proxyHeaders: false
},

redirect: [
{ from: '^/datenschutz-erklaerung', to: '/datenschutz' }
],

/*
** Build configuration
*/
build: {
extend(config) {
config.module.rules.push({
test: /bootstrap.native/,
use: {
loader: 'bootstrap.native-loader',
options: {
only: ['collapse', 'modal']
}
}
});
}
}
};

0
AlexBa
5
AlexBa
commented 7 months ago

Please note, that I can't report a bug with cmty.app, because there is no version to select in the sitemap module, but this field is required.

0
NicoPennec
1.7k
NicoPennec
commented 7 months ago

Can you give more details?

  • Nuxt.js version
  • node.js version
  • OS + version
  • command used to generate the sitemap (yarn generate or yarn build && yarn start)

Do you confirm that your sitemap config is empty?

Then, can you removed or disabled the other modules and retry?

To fix your issue quickly, you may use the following workaround:

```js
{
sitemap: {
filter ({ routes }) {
return routes.map(route => route.url = route.url.replace("/_nuxt", ""))
}
}
}

0
NicoPennec
1.7k
NicoPennec
commented 7 months ago

@AlexBa Ok, I reproduce when the sitemap: {}configuration object is missing.

0
NicoPennec
1.7k
NicoPennec
commented 7 months ago

@AlexBa for now the better way to fix your issue is to explicitly set the hostname option in your nuxt.config.js file:

{
  sitemap: {
    hostname: "https://alexanderbarton.de"
  }
}

I will check to improve your use case.

0
AlexBa
5
AlexBa
commented 7 months ago

@NicoPennec This code seems to work:

{
  sitemap: {
    hostname: "https://alexanderbarton.de"
  }
}

But this code doesn't work (I have tried it before):

{
  sitemap: {
    filter ({ routes }) {
      return routes.map(route => route.url = route.url.replace("/_nuxt", ""))
    }
  }
}

The commands, I tried, were: nuxt and nuxt generate

I just want to provide you some missing info. Maybe it can be helpful for later:

  • Node version: 11.7.0
  • Nuxt version: 2.4.5
  • OS version: maxOS 10.14.4

Thank you for your help!

0
NicoPennec
1.7k
NicoPennec
commented 7 months ago

Thanks for your answer with all details, but as explain before your last post, I found the issue.

It should be fixed since the release v1.1.0, see CHANGELOG

Please update your @nuxtjs/sitemap dependency to the latest release, remove your config `sitemap: { … } as before, and retry to generate the sitemap.

0
AlexBa
5
AlexBa
commented 7 months ago

It's working now with v1.1.0. Thank you again!

1
Informations
QuestionUnresolved
#c49 - Created 7 months ago