-
-
Save billyct/b28deb7afec4060a1b119546b9dc1eb3 to your computer and use it in GitHub Desktop.
Harmony with Laravel + Vue + Vue Router
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// dashboard component | |
var dashboard = Vue.extend({ | |
template: '<p>Hello from dashboard</p>' | |
}) | |
// user management component | |
var user = Vue.extend({ | |
template: '<p>Hello from user management page</p>' | |
}) | |
// 404 | |
var fourohfour = Vue.extend({ | |
template: '<p>Oh noes, four oh foes</p>' | |
}) | |
// create our vm instance | |
// set our template to display the component selected | |
// by the router | |
var app = Vue.extend({ | |
template: '<router-view></router-view>' | |
}) | |
// configure the router | |
// using HTML5 history mode | |
var router = new VueRouter({ | |
history: true, | |
saveScrollPosition: true, | |
root: '/admin' | |
}) | |
// map our frontend routes | |
router.map({ | |
'*': { | |
component: fourohfour | |
}, | |
'/dashboard': { | |
component: dashboard | |
}, | |
'/users': { | |
component: user | |
} | |
}) | |
// initialize the router and mount to #app | |
router.start(app, '#app') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Demo | Admin Panel</title> | |
</head> | |
<body> | |
<div id="app"> | |
</div> | |
<script src="//cdnjs.cloudflare.com/ajax/libs/vue/0.12.12/vue.min.js"></script> | |
<script src="//cdn.jsdelivr.net/vue.router/0.5.2/vue-router.min.js"></script> | |
<script src="/js/admin.js"></script> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// dashboard component | |
var dashboard = Vue.extend({ | |
template: '<p>Hello from dashboard</p>' | |
}) | |
// user management component | |
var user = Vue.extend({ | |
template: '<p>Hello from user management page</p>' | |
}) | |
// create our vm instance | |
// set our template to display the component selected | |
// by the router | |
var app = Vue.extend({ | |
template: '<router-view></router-view>' | |
}) | |
// configure the router | |
// using HTML5 history mode | |
var router = new VueRouter({ | |
history: true, | |
saveScrollPosition: true, | |
root: '/admin' | |
}) | |
// map our frontend routes | |
router.map({ | |
'/dashboard': { | |
component: dashboard | |
}, | |
'/users': { | |
component: user | |
} | |
}) | |
// initialize the router and mount to #app | |
router.start(app, '#app') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
get('admin/{subs?}', ['middleware' => 'auth', function () { | |
return view('admin'); | |
}])->where(['subs' => '.*']); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
get('admin/{subs?}', [function () { | |
return view('admin'); | |
}])->where(['subs' => '.*']); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment