首页 > 解决方案 > One-time redirect upon detecting Nuxt PWA in standalone mode

问题描述

I'm trying to achieve this, but no luck.

Here's the plugin. All three console logs are running correctly, including the 3rd-party platform.js functionality.

It's just the this.$route.router.go('/ourmenu') that isn't doing the redirect. I'm wondering if this is the right way to redirect in Nuxt, or if it needs to be done differently.

import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

window.onNuxtReady(() => {

    console.log('onNuxtReady!');
    console.log('platform test: ');
    console.log(platform.os.toString())

    if (platform.os.toString().includes('iOS') == true && window.navigator.standalone == true) {
        this.$route.router.go('/ourmenu');
    } else if (window.matchMedia('(display-mode: standalone)').matches) {
        this.$route.router.go('/ourmenu');
    } else {}

})

EDIT: I've also tried this.$router.push('/ourmenu') and context.redirect(${config.url}/ourmenu)

...Still a no go.

Any suggestions?

Thanks!

标签: vue.jsvuejs2vue-routernuxt.js

解决方案


找到了一个更简单的解决方案: Web App Manifest: start_url

Nuxt PWA 文档


推荐阅读