Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot read property 'substr' of undefined #10

Open
oinkbark opened this issue Jan 7, 2021 · 1 comment
Open

Cannot read property 'substr' of undefined #10

oinkbark opened this issue Jan 7, 2021 · 1 comment

Comments

@oinkbark
Copy link

oinkbark commented Jan 7, 2021

Version:
1.2.5

Config:

buildModules: [
    [ 'k-domains', { subDomains: [ 'api' ], rootDomain: 'root' } ],
    [ '@nuxtjs/router', { keepDefaultRouter: true } ]
  ]

Layout:

/pages
  /api
    index.vue
    api.pug
    api.styl
    api.ts
  /root
    index.vue
    /login
      index.vue
      login.pug
      login.styl
      login.ts
    /index
      index.pug
      index.styl
      index.ts

Error:

 ERROR  Cannot read property 'substr' of undefined 

  at server.js:1965:28
  at Array.map (<anonymous>)
  at createRouter (src/router.js:57:0)
  at router_createRouter (src/.nuxt/router.js:6:0)
  at createApp (src/.nuxt/index.js:69:0)
  at module.exports.__webpack_exports__.default (src/.nuxt/server.js:82:0)
  at node_modules/vue-server-renderer/build.prod.js:1:78608
  at new Promise (<anonymous>)
  at node_modules/vue-server-renderer/build.prod.js:1:78080
  at Object.renderToString (node_modules/vue-server-renderer/build.prod.js:1:81615)

I attached a console.log to route.path and route.name (line 57 on router.js) and this is what the output was:

/api
api
/api/api
api-api
/root
undefined
/root/login
root-login
/root/login/login
root-login-login

Possible Solution:
(I made this change manually to my setup and it made it work)
change this:

return {
  ...route,
  path: route.path.substr(routesDirectory.length + 1) || "/",
  name: route.name.substr(routesDirectory.length + 1) || "index"
}

to this: (add optional chaining)

return {
  ...route,
  path: route.path?.substr(routesDirectory.length + 1) || "/",
  name: route.name?.substr(routesDirectory.length + 1) || "index"
}
@madhusudanbabar
Copy link
Owner

Hey, thanks for pointing out that, I'll surely push an update.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants