我有一个vue应用程序与路由器设置如下:
import index from './components/index.vue';
import http404 from './components/http404.vue';
// module lazy-loading
const panda= () => import(/* webpackChunkName: "group-panda" */ "./components/panda/panda.vue");
// ...
export const appRoute = [
{
path: "",
name: "root",
redirect: '/index'
},
{
path: "/index",
name: "index",
component: index
},
{
path: "/panda",
name: "panda",
component: panda
},
//...
{
path: "**",
name: "http404",
component: http404
}
];
Run Code Online (Sandbox Code Playgroud)
所以熊猫模块是懒惰的.然而,当我导航到panda的页面,一个的console.log()this.$route.path中App.vue的mounted()生命周期仅输出
"/"
代替
"/熊猫"
但索引页面运行良好,它完全显示
"/指数"
正如所料.
那么,当页面最初加载时,Vue路由器如何才能正确获取延迟加载页面的当前路径?我错过了什么?
编辑:
但是,它可以在Webpack热重新加载后捕获正确的路径.它在第一次访问时捕获"/" …
而不是在 main() 下写每条路线,比如
func main() {
e := echo.New()
e.GET("/api", sayHello)
e.GET("/api/music", getMusic)
e.GET("/api/user/:id", getDetail)
e.POST("/api/user", addUser)
// ...
}
Run Code Online (Sandbox Code Playgroud)
如何从名为 的文件中导入所有这些子路由api.go,并在主函数中使用这些子路由?相似
import "./API"
func main() {
e := echo.New()
e.UseSubroute(API.Routes) // <-- similar to this
// ...
}
Run Code Online (Sandbox Code Playgroud)