Laravel Routing and Vue.js subdomains
I am using Laravel 5.4
, vue.js 2.3
and vue-router
.
Current situation
On impact example.com
, Laravel
returns the view app
that launchesVue.app
web.php
Route::get('/', function () {
return view('app');
});
app.js
const routes = [
{ path: '/', component: App },
];
const app = new Vue({
el: '#app',
router,
data () {
return {}
},
});
App.vue
export default {
...
}
What am i trying to do
If typed usa.example.com
, I would like it to display alert()
in mine .App.vue
usa
If typed italy.example.com
, I would like it to be shown alert()
in mine .App.vue
italy
I've read the documentation vue-router
, but I'm not sure if this is a problem Laravel
, a problem, Vue
or both.
App.vue
export default {
....
created() {
alert('subdomain is ' + $route.params.subdomain)
}
}
source to share
VueRouter doesn't keep track of the subdomain.
But you can get a subdomain from location
and use it in your component created
:
created() {
let subdomain = location.hostname.split('.').shift();
alert('subdomain is ' + subdomain);
}
This code is based on this answer .
source to share