如果您使用Vue CLI 3创建一个新的应用程序(具有路由器支持)并启动内置的开发服务器(根据您的喜好使用npm run serve或yarn yarn),则可以转到创建的/直接在浏览器中查看路线,它将加载。
在后台,内置开发服务器中的某些内容必须正在接受请求并将其路由到vue路由器。我想找出那是什么。
现在我已经完成了我的应用程序(https://github.com/insprintorob/libre)的开发,我想在自己的Express服务器中复制此功能。
但是,例如,如果我使用/ about静态服务静态网站应用时,请访问/ about,这会给您404错误,因为该路由未在express中注册。
vue-cli设置如何允许您直接转到路线,我如何使用express复制它?
答案 0 :(得分:0)
在后台,内置开发服务器中必须有一些东西 正在接受请求并将其路由到vue路由器。
路由器处理客户端上的页面,其中每条路由都与一个视图相关联。视图只是代表“页面”的组件。路由器允许创建单页应用程序。
// 1. Define route components.
const Foo = { template: '<div>foo</div>' }
const Bar = { template: '<div>bar</div>' }
// 2. Define some routes
// Each route should map to a component.
const routes = [
{ path: '/foo', component: Foo },
{ path: '/bar', component: Bar }
]
// 3. Create the router instance and pass the `routes` option
const router = new VueRouter({
routes // short for `routes: routes`
})
// 4. Inject the router with the router option on the root instance.
const app = new Vue({
router
}).$mount('#app')