Q:

Direct url not working in vuejs but router push works

When i load the component localhost:8080/scan using this.$router.push(), url loads with the component But when i do npm run build and then http-server dist/, the url localhost:8080/scan doesn't work, gives a 404.
Any idea why it works in dev and not after build.
I did check online and found it was a nginx issue but i tried adding try_files $uri $uri/ /index.html; as per this doc: https://router.vuejs.org/en/essentials/history-mode.html but nothing seems to work. Any help is much appreciated.

A:

Please post your complete code to the question, or a github repository. Otherwise it's hard to guess what's your issue.
If I had to guess - your http-server can't find scan.html because it doesn't exist. You have a few options:

Use hash mode which won't require the /scan url and rely on /index.html#scan instead.
Use a node-js server with defined routes that go to your html page. Or just send all of them to the same page. Here's an example https://github.com/ubershmekel/redditp/blob/1e9a659bcc34fa2f2dc28deb552b6702a1173cc1/app.js#L12
Use Nuxt or do something like Nuxt does - build all the html files so you can still use a static server like http-server. See https://nuxtjs.org/guide#static-generated-pre-rendering- For example you can copy your index.html to scan.html manually.

