vue 去掉访问地址#(八)

const router = new VueRouter({ mode: 'history', routes: routers })
main.js 与 router.js同级目录

router.js
import Hello from './components/Hello' import NetWork from './components/netWork' import NotFoundComponent from './components/notFoundComponent' import Home from './components/home' import First from './components/first' import Login from './components/login' const routers = [ { path: '/', name: 'Hello', component: Hello }, { path: '/data', name: 'NetWork', component: NetWork }, { path: '/home/', name: 'home', component: Home, children: [ { path: '/', component: Login }, { path: 'first', name: 'first', component: First } ] }, { path: '*', component: NotFoundComponent } ] export default routers
main.js
// The Vue build version to load with the `import` command // (runtime-only or standalone) has been set in webpack.base.conf with an alias. import Vue from 'vue' import VueRouter from 'vue-router' import Resource from 'vue-resource' import routers from './router.js' import App from './App' import rootPath from './config/api.js' //Vue.config.productionTip = false Vue.use(VueRouter) Vue.use(Resource) Vue.http.interceptors.push(function(request, next) {//拦截器 // 跨域携带cookie request.credentials = true; next() }) const router = new VueRouter({ mode: 'history', routes: routers }) /* eslint-disable no-new */ new Vue({ el: '#app', router, template: '<App/>', components: { App }, data: { urlPath : rootPath.pathUrl() } })
具体参考来源
http://www.cnblogs.com/wisewrong/p/6277262.html
http://www.cnblogs.com/zhuzhenwei918/p/6892066.html
浙公网安备 33010602011771号