[英]The extendRoutes function is not being called in nuxt.config.js
我已经使用Vue-Storefront生成了一个商店,它使用了 Nuxt ,并且在Layout and Routing文档页面中,建议使用extendRoutes :
require("isomorphic-fetch");
import webpack from "webpack";
const platformENV = process.env.NODE_ENV !== "production" ? "http" : "https";
const config = {
// here ------------------------------
router: {
extendRoutes(routes, resolve) {
routes.push({
name: "custom",
path: "/test",
component: resolve(__dirname, "pages/Category.vue"),
});
},
},
// here ------------------------------
...
};
export default config;
问题是extendRoutes 永远不会被调用,因为其中没有触发控制台日志,而且我不确定如何解决这个问题。 路由未创建或重命名,它路由到 404 页面。 如果有帮助,我正在链接我的 package.json 的某些部分:
"dependencies": {
"@nuxt/image": "0.6.0",
"@nuxtjs/pwa": "^3.3.5",
"@nuxtjs/sitemap": "^2.4.0",
"@nuxtjs/style-resources": "^1.0.0",
"@storefront-ui/vue": "^0.12.0",
"@vue-storefront/shopify": "^1.1.2",
"@vue-storefront/middleware": "2.5.6",
"@vue-storefront/nuxt": "2.5.6",
"@vue-storefront/nuxt-theme": "2.5.6",
"cookie-universal-nuxt": "^2.1.3",
"core-js": "^3.19.1",
"isomorphic-fetch": "^2.2.1",
"nuxt": "^2.13.3",
"@nuxtjs/i18n": "^7.2.1",
"vee-validate": "^3.2.3",
"vue-scrollto": "^2.17.1",
"@nuxtjs/device": "^2.1.0",
"ipx": "0.9.1"
},
"devDependencies": {
"@nuxt/types": "^2.13.3",
"@nuxt/typescript-build": "^2.0.0",
"@vue/test-utils": "^1.0.0-beta.27",
"babel-jest": "^24.1.0",
"cypress": "^9.1.0",
"ejs": "^3.0.2",
"jest": "^27.4.3",
"lint-staged": "^11.1.2",
"start-server-and-test": "^1.14.0",
"vue-jest": "^4.0.0-0"
}
如果有人遇到同样的问题,有想法,请告诉我。
在尝试摆脱 @kissu 评论的部分代码后,我找到了答案。 问题来自"./modules/cms/build"
,在nuxt.config.js的buildModules中,这一行调用了已经集成的 cms 的构建脚本,它替换了router.extendRoutes function 并制作了自己的路由。
buildModules: [
// to core
"./modules/cms/build",
"@nuxtjs/composition-api/module",
...
我希望这可以帮助那里的人!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.