Skip to content
This repository was archived by the owner on Dec 31, 2024. It is now read-only.

[solved] v-t directive needs custom directive to work with SSR #293

Closed
DaxChen opened this issue Feb 3, 2018 · 5 comments
Closed

[solved] v-t directive needs custom directive to work with SSR #293

DaxChen opened this issue Feb 3, 2018 · 5 comments

Comments

@DaxChen
Copy link

DaxChen commented Feb 3, 2018

vue & vue-i18n version

[email protected] (with [email protected])
[email protected]

Reproduction Link

Online Demo
Github Repo

Steps to reproduce

Open the online demo link:

  1. refresh and see that {{ $t('xxx') }} shows immediately (SSR) but v-t="'xxx'" shows a bit later (no SSR)
  2. Right-click and "View page source", and you can see this:
<h1 class="curly_bracket">Using {{ }}, shows in SSR!</h1>
<h1 class="directive"></h1>

Only {{ $t() }} is server side rendered, v-t="'xxx" isn't.

What is Expected?

v-t directive to work nicely with SSR

What is actually happening?

contents using v-t don't show in SSR result, which makes:

  1. Not good for SEO.
  2. First page load experience is not good, need to wait for js to render in client side.
  3. Content will not show if javascript is disabled.
@DaxChen
Copy link
Author

DaxChen commented Feb 3, 2018

Hi, @kazupon.
Can you estimate if this will be fixed in soon?
Not to push or anything, just that if this will take relatively long to fix, I need to temporarily change all v-t to $t() throughout SEO important parts.

@darkylmnx
Copy link

according to the docs :

Also, when you use server-side rendering, you need to set the custom directive to directives option of the createRenderer function.

https://kazupon.github.io/vue-i18n/en/directive.html#t-vs-v-t

@DaxChen DaxChen closed this as completed Feb 3, 2018
@DaxChen
Copy link
Author

DaxChen commented Feb 3, 2018

Whoa!!!! How did I missed that?!! I've read that page like 20 times before...orz
Thank you so much @darkylmnx! Sorry for the interruption.

@DaxChen DaxChen changed the title v-t directive doesn't work with SSR, only $t('') works. [solved] v-t directive needs custom directive to work with SSR Feb 3, 2018
@DaxChen
Copy link
Author

DaxChen commented Feb 3, 2018

example usage with nuxt, see: nuxt/nuxt#1826 (comment)

@DaxChen
Copy link
Author

DaxChen commented Feb 4, 2018

Found that the SSR custom directive only works with primitive html tags, but not with vue components such as <router-link>.
Opened issue: intlify/vue-i18n-extensions#1

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

No branches or pull requests

2 participants