Angular 5 & Go Web 服务

Angular 5 & Go Webservices

Angular 5 作为前端 & 后端作为 Golang 和编写 Services in go 当页面刷新时,请求被发送到服务器,导致页面未找到 404 错误,因为请求绕过 angular.

中的路由器

例如:如果我们调用 /login,我们可以从路由中显示一个页面,但如果刷新相同的页面,则会显示为找不到页面 404。

Angular5:

const AppRoutes: Routes = [
          { path: '/', component: SignupComponent, pathMatch: 'full' },
          { path: 'login' , component: LoginComponent },
          { path: 'home' , component: VisitsComponent},
          { path: 'createavisit/:id', component: VisitComponent},
      ];

前往:

http.Handle("/", http.FileServer(http.Dir("./angular/dist")))
    http.HandleFunc("/register", RegisterHandler)
    http.HandleFunc("/log", LoginHandler)

谁能帮我解决这个问题

在导入路由模块的应用程序模块文件中添加 useHash:true 参数。例如:RouterModule.forRoot(routes, {useHash: true})