question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Route params in ssr

See original GitHub issue

Forgive me for opening a new problem, but I did not understand how it is possible to get on the server in the lower levels of components where I will call ServerPrefetch () and receive data in Vieks and transfer data from the router there. Example:

<script>
import { mapState, mapActions } from 'vuex'

export default {
  name: 'SearchBar',
  serverPrefetch() {
    return this.getSearch()
  },
  mounted() {
    if(!this.searchLocation && !this.searchCategory)
        this.getSearch()
  },
  computed: {
    ...mapState('application', ['viewPort', 'categories']),
    ...mapState('search', ['searchCategory', 'searchLocation', 'searchLoading'])
  },
  methods: {
    ...mapActions('search', ['setSearch']),
    getSearch() {
      if(this.$route && this.$route.params && (!this.searchCategory || !this.searchLocation))
        return this.setSearch({
          location: this.$route.params.location ? this.$route.params.location : null,
          category: this.$route.params.category ? this.$route.params.category : null
        })
      else return null
    },
    toSearch() {
      window.location.href = `/search/${
        this.searchLocation && this.searchLocation.nameEnLowercase
          ? this.searchLocation.nameEnLowercase : 'all_cities'
      }/${
        this.searchCategory && this.searchCategory.translit
          ? this.searchCategory.translit : 'all_categories'
      }`
    }
  }
}
</script>

I see route params in *.page.server.js contextProps.url but how I can recive this parameters in components in serverPrefetch()

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
gryphonmyerscommented, Apr 7, 2021

BTW I have full guidance for vue router integration in progress. This will become far more straightforward once I’ve finished

0reactions
brilloutcommented, Apr 10, 2021

Thanks for sharing; I added your solution to the docs.

Let me know if you have any other question!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Implementing SSR in Next.js: Dynamic routing and prefetching
In addition to SSR support, Next.js offers link prefetching and dynamic ... params contains all the route parameters and their values.
Read more >
react router server side rendering: How to get route params on ...
I having big time dealing with react-router with parameters. I cannot extract routes params from route on server side to make proper query ......
Read more >
Dynamic Routes - Next.js
Dynamic Routes are pages that allow you to add custom params to your URLs. Start creating Dynamic Routes and learn more here.
Read more >
Server Side Rendering with route param not working #27596
After building another time with npm run buid:ssr (angular and node), I've got no more issue with the route param. But the origin...
Read more >
Route String - vite-plugin-ssr
We can define multiple parameters. // /pages/film.page.route.js // Parameters available at: ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found