VUE Router not working with two Electron BrowserWi

2019-09-18 21:56发布

I’m trying to create an app with two BrowserWindows using the same Vue App with vue-router, but the router aren’t working. I’m always receiving error ‘Cannot GET /’ for the second route.

main\index.js

var mainURL = `http://localhost:9080/`
var secondURL = `http://localhost:9080/page2`

function createWindow () {
  mainWindow = new BrowserWindow({
    height: 600,
    width: 800
  })
  mainWindow.loadURL(mainURL)
  mainWindow.on('closed', () => {
    mainWindow = null
  })

  secondWindow = new BrowserWindow({
    height: 600,
    width: 800
  })
  secondWindow.loadURL(secondURL)
  secondWindow.on('closed', () => {
    secondWindow = null
  })
}

app.on('ready', createWindow)

routes.js

export default [
  {
    path: '/',
    name: 'landing-page',
    component: require('components/LandingPageView')
  },
  {
    path: '/page2',
    name: 'landing-page2',
    component: require('components/LandingPageView2')
  },
  {
    path: '*',
    redirect: '/'
  }
]

Testing code: https://github.com/melquic/vue-two-windows.git

Error print screen:

enter image description here

Thank you for help! Best.

1条回答
戒情不戒烟
2楼-- · 2019-09-18 22:17

The URL needs to be http://localhost:9080/#/page2 in order to make this work.

查看更多
登录 后发表回答