简体   繁体   English

如何使 vue-routes 工作

[英]How to make vue-routes works

I'm trying to setup routes with tutorial.我正在尝试使用教程设置路线。 I have this code but any data not imports to the selected page(/home).我有这个代码,但没有导入到所选页面(/home)的任何数据。 Any idea how to fix it?知道如何修复它吗? This is my code:这是我的代码:

App.js应用程序.js

import VueRouter from 'vue-router';
import router from "./router";
import App from "./components/App";
import Test from "./components/test";
window.Vue = require('vue');
Vue.use(VueRouter);
const app = new Vue({
    el: '#app',
    render : h => h(App),
    router
});
@endsection

pastebin: https://pastebin.com/7yMREHxR pastebin: https : //pastebin.com/7yMREHxR

https://codesandbox.io/s/hungry-browser-hsi6d https://codesandbox.io/s/hungry-browser-hsi6d

Change改变

import Vue from "vue";
import VueRouter from "vue-router";
import Test from "./components/Test";

Vue.use(VueRouter);

export default new VueRouter({
  routes: [
    {
      path: "/home",
      component: Test
    }
  ]
});

to

import Vue from "vue";
import VueRouter from "vue-router";
import Test from "./components/Test";

Vue.use(VueRouter);

export default new VueRouter({
  routes: [
    {
      path: "/",
      component: Test
    }
  ]
});

The key take away here is the path property.这里的关键是路径属性。 You set it to "/home".您将其设置为“/home”。 So your app worked but only when you navigated to "localhost:xxxx/home/" by changing it to "/" it becomes your root view.因此,您的应用程序可以正常工作,但只有当您通过将其更改为“/”来导航到“localhost:xxxx/home/”时,它才会成为您的根视图。 Check out this sand box to play with the solution:看看这个沙盒来解决这个问题:

编辑 Dora28noFake 的答案

Hope this helps!希望这可以帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM