Wrong routes with /_nuxt/ prefix in sitemap

AlexBa
5
AlexBa
commented a year 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 a year 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
2.1k
NicoPennec
commented a year 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
2.1k
NicoPennec
commented a year ago

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

0
NicoPennec
2.1k
NicoPennec
commented a year 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 a year 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
2.1k
NicoPennec
commented a year 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 a year ago

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

1
tommcclean
0
tommcclean
commented 9 months ago

I experienced this issue when installing the module, adding to the end of my modules: [] without any further configuration.

When looking at the sitemap on my local machine, it was fine; but when deployed it contained /_nuxt/ for each route.

In my case it was actually worse, as I was using a CDN as a publicpath, so the path actually pointed to a _nuxt route on my CDN endpoint.

I was also using i18n with several languages.

Can confirm that adding a sitemap: { hostname: "https://cmpct.io" } fixed the issue as described in this issue.

I was on version 2.0.1

0
NicoPennec
2.1k
NicoPennec
commented 9 months ago

@tommcclean I need more details to reproduce the issue

  • Can you share your nuxt.config.js?
  • Do you have a custom build: { publicPath: "..." } on production in your nuxt.config.js?
  • Which mode did you use? (Universal / SPA / Generate)
  • How did you deploy your nuxt project?
0
Informations
Question โ€ข Unresolved
#c49 - Created a year ago