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

Segment undefined in the context of a middleware #13

Open
sandoche opened this issue Jan 28, 2021 · 10 comments
Open

Segment undefined in the context of a middleware #13

sandoche opened this issue Jan 28, 2021 · 10 comments
Assignees
Labels
bug Something isn't working

Comments

@sandoche
Copy link

sandoche commented Jan 28, 2021

Hi,
I am trying to use segment from the context, in a middleware loaded from a layout and it does not work.

Segment undefined in the context in a middleware

export default function({ app, $segment }) {
  console.log($segment)
  console.log(app.$segment)
}
@gaelreyrol
Copy link
Contributor

Hi @sandoche !

Can you provide your configuration ?

@sandoche
Copy link
Author

In nuxt.config.js

modules: [
    // ...
    '@dansmaculotte/nuxt-segment'
  ],

  segment: {
    writeKey: process.env.SEGMENT_WRITE_KEY,
    disabled: false,
    useRouter: true
  }

When I use it in a page in mounted with this.$segment it does work.

@sandoche
Copy link
Author

I am using Nuxt.js @ v2.14.7

@gaelreyrol
Copy link
Contributor

Do you any error logs ?

@sandoche
Copy link
Author

When I run a page with this middleware of a layout I have this:
undefined (two times)

No other errors.
When I use this.$segment in the mounted of a page it works perfectly.

@sandoche
Copy link
Author

I tried to move the middleware in the page instead of the layout and it's the same

@gaelreyrol
Copy link
Contributor

So it's working in a page but not in a middleware or a layout ?

@sandoche
Copy link
Author

Exactly. It works in the mounted of the page. It also works automatically also for each page.

It does not work as a middleware (either for the page of the layout)

@gaelreyrol
Copy link
Contributor

Okay, I will try to look at it soon !

@gaelreyrol gaelreyrol self-assigned this Jan 28, 2021
@gaelreyrol gaelreyrol added the bug Something isn't working label Jan 28, 2021
@sandoche
Copy link
Author

Thanks for now, I'll run the code on the mounted of the layout, it seems that this works. But I would have a cleaner code by having it in a middleware.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

No branches or pull requests

2 participants