caoxiemeihao / nuxt-electron

Integrate Nuxt and Electron
MIT License
184 stars 21 forks source link

file:// Protocol Causes Page Routing Error #65

Closed MangMax closed 5 months ago

MangMax commented 9 months ago

! PixPin_2023-12-24_23-16-59

When I start it for the first time it doesn't load the home page correctly, when I go to the home page via nuxt and then refresh it, the page loads wrong again, how can I fix this problem please!

vuthanhbayit commented 8 months ago

same isssue

Semolik commented 8 months ago

same problem

vuthanhbayit commented 8 months ago

! PixPin_2023-12-24_23-16-59

When I start it for the first time it doesn't load the home page correctly, when I go to the home page via nuxt and then refresh it, the page loads wrong again, how can I fix this problem please!

This is my temporary issue:

import path from 'path'
import { createServer } from 'http'
import handler from 'serve-handler'
import { app, BrowserWindow } from 'electron'

process.env.ROOT = path.join(__dirname, '..')
process.env.DIST = path.join(process.env.ROOT, 'dist-electron')
process.env.VITE_PUBLIC = path.join(process.env.ROOT, '.output/public')
process.env.ELECTRON_DISABLE_SECURITY_WARNINGS = 'true'

const preload = path.join(process.env.DIST, 'preload.js')
let win: BrowserWindow

function bootstrap() {
  win = new BrowserWindow({
    webPreferences: {
      preload,
      nodeIntegrationInWorker: true,
      contextIsolation: false,
      nodeIntegration: true,
      webSecurity: false,
    },
  })

  if (process.env.VITE_DEV_SERVER_URL) {
    win.loadURL(process.env.VITE_DEV_SERVER_URL)
    win.webContents.openDevTools()
  } else {
    const server = createServer((req, res) => {
      return handler(req, res, {
        public: process.env.VITE_PUBLIC,
      })
    })

    server.listen(1111, () => {
      win.loadURL('http://localhost:1111/')
    })
  }
}

app.whenReady().then(bootstrap)
creazy231 commented 8 months ago

adding

router: {
  options: {
    hashMode: !process.env.VITE_DEV_SERVER_URL,
  },
},

to my nuxt.config.ts fixed the problem

MangMax commented 5 months ago

Thanks, it's been resolved!