Last active
May 15, 2018 19:41
-
-
Save jwalton512/9f1af52981dcbd236274 to your computer and use it in GitHub Desktop.
Harmony with Laravel + Vue + Vue Router
This file contains 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 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 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 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 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' => '.*']); |
Can you please explain, how to use http get with this method? If i use this subs method then i no longer get response from database
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Could you explain what that routes.php GET method does? Is there to avoid 404s from direct links to routes defined by vue router?