Open ziadsarour opened 5 months ago
After reviewing the code, I know $pwa.isPWAInstalled
means "I'm inside a PWA" based on https://github.com/vite-pwa/nuxt/blob/106977993291d2443d52569b335f78e8a03e0a69/src/runtime/plugins/pwa.client.ts#L18-L29
I also have a local module which generate manifests based on the one generated by this plugin :
This local module is specific to my website but here is a snippet you could be inspired of :
...
const directory = path.join(__dirname, '..', '.output', 'public');
const baseManifest = getBaseManifest({ directory });
for (const locale of locales) {
saveManifest({
directory,
locale: locale.code,
manifest: {
...baseManifest,
description: t.description[locale.code] || baseManifest.description,
start_url: locale.url,
},
});
}
...
function getBaseManifest(options: {
directory: string;
}) {
const filepath = path.join(options.directory, 'manifest.webmanifest');
const file = fs.readFileSync(filepath, { encoding: 'utf-8' });
if (!file) {
throw `module webmanifests: missing base manifest file`;
}
return JSON.parse(file);
}
function saveManifest(options: {
directory: string;
locale: RegionLocale['code'];
manifest: any;
}) {
const filepath = path.join(options.directory, options.locale, 'manifest.webmanifest');
fs.writeFileSync(filepath, JSON.stringify(options.manifest), { encoding: 'utf-8' });
}
Be sure to remove your
I now need to resolve 2.
Hi and thank you for this plugin !
I have an i18n website using @nuxtjs/i18n with a dropdown to switch locale. It's working fine on my website Inside my PWA, if I switch the locale manually and navigate through the app, it's working great. But whenever I close the app, I'm falling back to the default locale.
Here is my
nuxt.config.ts
It think it's because
start_url
is pointing to the default locale, so I will always be opening my PWA using the default locale. I've seen someone suggesting localized webmanifests generation https://github.com/vite-pwa/nuxt/issues/52, would be great but once the PWA is installed it will not be possible to switch the locale becausestart_url
is static.I am thinking about checking at startup if I'm inside the PWA, if yes, redirect to the correct localized route using
useI18n().locale
.But :
useI18n().locale
will be set to the default locale before my check because ofskipSettingLocaleOnNavigate: false
My questions :
$pwa.isPWAInstalled
or it is just a flag to know if I have the PWA installed on my device ?useI18n().locale
is not correct I will have to persist the user locale manually, how can I do this with a PWA ?