[英]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.