Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Router part of PWA opens blank on device (with Vue)

I built 2 PWA based on Vue (with Vue UI templates, with router and PWA already set up) but I get on both the same issue: after I add to Homescreen on device, when I open it from the app icon, the router viez doesn't show up and stays blank until I click on a router link. I don't understand why.

Example of one of them, my portfolio:

URL Link

GitHub Link

Some parts of files here that I think related to the issue:

router.js:

export default new Router({
  mode: 'history',
  base: 'index.html',
  routes: [
    {
      path: '/',
      name: 'home',
      component: Home
    }
  ]
})

firebase.json:

"rewrites": [
  {
    "source": "**",
    "destination": "/index.html"
  }
]
like image 808
LightBen Avatar asked Oct 31 '18 21:10

LightBen


People also ask

How do I access my vue router in component?

To have the Vue-Router routes be rendered you will need to pass the <router-view> tag inside a Vue component. You could also access the routes from an <a> tag, but this will trigger a page re-render, to avoid this behavior you could use router-link with the to property instead of a href .

Is vue good for PWA?

Vue CLI offers a convenient PWA plugin, and, even better, it can be added to an existing or new project.


2 Answers

Edit: Checkout @webmint answer below, probably solve problem im better and clean way.

Orginal Post:

I solved my problem adding an alias to start page in routes (in my case "Login")

in manifest.json:

{
...
"start_url": "index.html",
...
}

in router config:

let router = new Router({
...
  routes: [
    {   path: '/index.html',
        component: Login,
        alias: '/'
    },
    {
        path: '/',
        name: 'login',
        component: Login
    },
...
like image 177
kaligari Avatar answered Oct 24 '22 10:10

kaligari


Had same issue. Turns out that solution is quite simple. You have to add/change this in manifest.json

"start_url": "/",
"scope": "/"
like image 7
webmint Avatar answered Oct 24 '22 10:10

webmint