SPA pattern for localized redirection using Nuxtjs and i18n
P粉071626364
2023-08-28 13:53:37
<p>When I generate Nuxtjs in SPA mode (SSR: false), there is no index.html file in the dist folder generated by nuxt. </p>
<p>So I have two questions</p>
<p><strong>1st: I need to redirect to lang folder, for example exmple.com redirect to exmaple.com/{locale}</strong></p>
<p><strong>2nd: I need to redirect for subpages, for example exmple.com/admin to exmaple.com/{locale}/admin</strong></p>
<pre class="brush:php;toolbar:false;">// nuxt.config.js
...
i18n: {
lazy: true,
langDir: 'lang/',
locales: [
{
code: 'en',
iso: 'en-US',
file: 'en.js',
name: 'English'
},
{
code: 'ar',
iso: 'ar-EG',
file: 'ar.js',
name: 'عربى'
}
],
defaultLocale: {
locale: 'en',
prefix: true
},
...</pre></p>
I have an idea to solve this problem, but I don't know if it is the best solution.
Just use
.htaccess
to handle the request and return the desired index.