获取NUXT配置文件中的路由路径名

发布于 2025-01-27 22:54:15 字数 810 浏览 2 评论 0原文

我有应用程序,我正在与Sitemap Generation一起玩。 对于SiteMap,我使用 @nuxtjs/stitemap -2.4.0,我的想法是只有在用户打开站点映射URL而不是在服务器的每个启动时,才能运行一些功能以动态生成站点地图。

我正在使用NUXT/VUE-APP 2.15.8,我想知道访问NUXT配置文件中当前打开的页面/路径的正确方法是什么?

这是SiteMap本身的配置:

{
    path: '/sitemaps/store-locations.xml',
    exclude: ['!**', '/'], // Skip all automatically generated routes
    i18n: true,
    xmlNs:
      'xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml"',
    routes: async function () {
      //$route gets undefined
      if (this.$route.path.split('/').pop() !== 'store-locations.xml') return
      
      //heavy functions which makes a lot of calls to DB
      const { getStores } = require('../../helpers/sitemap/storeLocatorRoutes');

      return getStores();
    },

I have app and I am playing around with sitemap generation.
For sitemap I am using @nuxtjs/sitemap - 2.4.0, and my idea is to run some functions for generating sitemaps dynamically only when user opens site map URL and not on every startup of server.

I am using nuxt/vue-app 2.15.8 and I was wondering what is the correct way to access current opened page/path inside Nuxt config file ?

This is config for sitemap itself:

{
    path: '/sitemaps/store-locations.xml',
    exclude: ['!**', '/'], // Skip all automatically generated routes
    i18n: true,
    xmlNs:
      'xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml"',
    routes: async function () {
      //$route gets undefined
      if (this.$route.path.split('/').pop() !== 'store-locations.xml') return
      
      //heavy functions which makes a lot of calls to DB
      const { getStores } = require('../../helpers/sitemap/storeLocatorRoutes');

      return getStores();
    },

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文