Vue-cli-plugin-electron-builder: Use the shortcut key to refresh the page after the page blank

Created on 15 Apr 2019  ·  5Comments  ·  Source: nklayman/vue-cli-plugin-electron-builder

When I finished packaging my project, I refreshed the page with the menu role= 'reload' shortcut provided by the electron official, the page was blank.While In development mode, it is normal to use the shortcut key to reload the page.
{ label:'刷新', role:'reload' },
When I debug my packaged project, after refreshing the page, the debug found.
The refresh before:
image
After the refresh:
image

Most helpful comment

router用history模式的情况下会出现这种情况。
测试了几个版本都有这个问题,具体原因不清楚,但桌面软件一般都是禁止用户手动刷新的吧
如果确实有这个需求,将vue-router改为hash模式

All 5 comments

router用history模式的情况下会出现这种情况。
测试了几个版本都有这个问题,具体原因不清楚,但桌面软件一般都是禁止用户手动刷新的吧
如果确实有这个需求,将vue-router改为hash模式

So do I

This is because routed path will not resolve to ./index.html

Replace createPorotocol('app') with:

protocol.registerBufferProtocol(
      'app',
      (req, cb): void => {
        const send = (p: string): void => {
          fs.readFile(
            path.join(__dirname, p),
            (error, data): void => {
              if (error) {
                return send('index.html');
              }
              const extension = path.extname(p).toLowerCase();
              // Used files mime types, reference:
              // https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Complete_list_of_MIME_types
              const types: Record<string, string | undefined> = {
                '.js': 'text/javascript',
                '.html': 'text/html',
                '.css': 'text/css',
                '.svg': 'image/svg+xml',
                '.svgz': 'image/svg+xml',
                '.json': 'application/json',
                '.woff': 'font/woff',
              };
              const mimeType = types[extension];
              if (!mimeType) {
                throw new Error(`Unknown file type: ${p}`);
              }

              cb({ mimeType, data });
            }
          );
        };

        send(decodeURI(new URL(req.url).pathname));
      },
      (err: Error): void => {
        console.log({ level: 'ERROR', err });
      }
    );

Tested on my end.

Maybe there should be a fallback option for createProtocol function

Electron has ctrl-r to reload enabled by default and it works fine.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sanch941 picture sanch941  ·  6Comments

mrin9 picture mrin9  ·  6Comments

devlerone picture devlerone  ·  4Comments

fridzema picture fridzema  ·  4Comments

grantdfoster picture grantdfoster  ·  3Comments