vue.js - vue-router in production (serving with Go) -


i'd separate client , server completely, created vuejs project vue init webpack my-project. in project i'm using vue-router routing (this includes special paths, /user/someid..

this routes.js file:

import app './app.vue'  export const routes = [   {     path: '/',     component: app.components.home   },   {     path: '/user/:id',     component: app.components.userid   },   {     path: '*',     component: app.components.notfound   } ] 

when run application using npm run dev works perfectly. i'm ready deploy cloud, ran npm run build. since need use http server, decided use go well.. go file:

package main  import (     "fmt"     "github.com/go-chi/chi"     "github.com/me/myproject/server/handler"     "net/http"     "strings" )  func main() {     r := chi.newrouter()      distdir := "/home/me/code/go/src/github.com/me/myproject/client/dist/static"     fileserver(r, "/static", http.dir(distdir))      r.get("/", indexget)      http.listenandserve(":8080", r) }  func indexget(w http.responsewriter, r *http.request) {     handler.render.html(w, http.statusok, "index", map[string]interface{}{}) }  func fileserver(r chi.router, path string, root http.filesystem) {     if strings.containsany(path, "{}*") {         panic("fileserver not permit url parameters.")     }      fs := http.stripprefix(path, http.fileserver(root))      if path != "/" && path[len(path)-1] != '/' {         r.get(path, http.redirecthandler(path+"/", 301).servehttp)         path += "/"     }     path += "*"      r.get(path, http.handlerfunc(func(w http.responsewriter, r *http.request) {         fs.servehttp(w, r)     })) } 

i'm able load home page (app.components.home) seem work (the css, images, translations, calls , responses server).. when try open other routes should either result in 404 or load user, response 404 page not found in plaintext (not vue notfound component it's supposed render)..

any ideas i'm doing wrong , how fix it?


edit: other part of router setup in main.js file:

const router = new vuerouter({   mode: 'history',   base: __dirname,   routes })  new vue({   el: '#app',   router,   i18n,   render: h => h(app) }) 

i might wrong, maybe routes trying visit gets resolved in server (in go http server).

you can try remove mode: 'history' in vue-router initialization defaults hash mode (the routes resolve in browser). please see this link.


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -