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.

some params is missing when use localePath

See original GitHub issue

My reload params is missing to nuxt-link like this <nuxt-link :to="localePath({ name: 'foo', params: { foo: 'nice', reload: true } })"> this.$router.push(localePath({ name: 'foo', params: { foo: 'nice', reload: true } }))

It’s working fine below. No params are lost. <nuxt-link :to="{ name: 'foo', params: { foo: 'nice', reload: true } }"> this.$router.push({ name: 'foo', params: { foo: 'nice', reload: true } })

<div align="right">This question is available on Nuxt.js community (#c27)</div>

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:5
  • Comments:8

github_iconTop GitHub Comments

11reactions
urbgimtamcommented, Feb 13, 2019

I use a similar strategy to link to a child url (for SEO purposes), but also passing an id that I use to fetch data from.

Without i18n, you can do <nuxt-link :to="{name: 'thepage-url', params: {id: '123', url: 'abced' }"} /> which will give you access to both parameters in $routes.params object on the child page.

However, with i18n, when you write: <nuxt-link :to="localePath({ name: 'thepage-url', params: {id: '123', url: 'abced'} }) you only access the parameter used for the ‘slug’ definition (this case, ‘url’).

Have to use the alternative presented by @azeranex to make it work (thanks!), but feels like a hack. Edit: here’s what I use for Nuxt 2.4.0 and above:

<nuxt-link
    :to="{
            name: `thepage-url___${$i18n.locale}`,
            params: {
              url: 'abced',
              nid: '123',
              fulldata: anObjWithData   // you can also pass an object with a good bunch of data, if needed.
            }
         }" />

IMO localePath() should deal only with the ‘name’, like <nuxt-link :to="{ name: localePath('thepage-url'), params: { [ all we need here ]} }) />

What’s the benefit of passing the full params object into the function localePath?

6reactions
azeranexcommented, Mar 17, 2018

I use reload param to check whether I need to fetch api data and fill vuex store or not. You can use query to track too but when you use ajax to fill more data (e.g. infinite scroll) your page will be reload to first data if you view item on other page and click back. You ajax content got wiped. Your scroll position lost.

If you store reload var in param you data still intact.

I can solve my problem by using (it’s work fine) <nuxt-link :to="{ name: `listing-${$i18n.locale}`, params: { listing: 'rent', reload: true } }" class="navbar-item">{{ $t('navbar.rent') }}</nuxt-link>

Read more comments on GitHub >

github_iconTop Results From Across the Web

some params is missing when use localePath #43 - GitHub
My reload params is missing to nuxt-link like this this.$router.push(localePath({ name: ... some params is missing when use localePath #43.
Read more >
vue.js - How to access route params: through a fully nuxt-i18n ...
PS: localePath alone will not work because it will return a full path but you cannot use params with a path as explained...
Read more >
Basic Usage - i18n-module
localePath – Returns the localized URL for a given page. The first parameter can be either the path or name of the route...
Read more >
Rails Internationalization (I18n) API - Ruby on Rails Guides
The i18n library takes a pragmatic approach to locale keys (after some discussion), including only the locale ("language") part, like :en , :pl...
Read more >
AnnotationClassLoader.php | Drupal 9.1.x | Drupal API
Most of the * time, this method should define some PHP callable to be called for the route ... $localePath; } } elseif...
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