2

I am currently trying to pass an array thats accessible on one page to the next. The next page is accessed on a forms submission using this.$router.push('path')

Is there any way for me to pass the array over as well when submitting the form so that I can access it on the new page?

1

2 Answers 2

2

You can't do that with Vue router directly as explained in this answer, you can only pass String type.

If you want to access it on another page, you can either:

  • store it in cookies or localStorage (not recommended)
  • fetch it from the submission: the backend probably gives you a response
  • use Vuex or even some state that can overlap between the current and next page
Sign up to request clarification or add additional context in comments.

2 Comments

Is there anyway to pass a string but not have it visible in the URL?
All of the 3 methods above do not use the URL (the state is invisible for the end user). If you POST something, you can send a body yeah, but this is unrelated to what you're trying to achieve here. I mean, it is somehow related to my 2nd solution but still not directly what you're asking for here. @blue4euro4
0

If you don't wanna use vuex or other store managers then the simplest way could be doing

this.$router.push('path').then(() => { this.$route.params.yourArray = ['value'] })

and then in the destination component use that same

this.$route.params.yourArray

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.