vue-meteor
vue-meteor copied to clipboard
vue-router from NPM or akryum:vue-router2?
When trying to run the following code in a Meteor+Vue SSR app:
import { RouterFactory, nativeScrollBehavior } from 'meteor/akryum:vue-router2'
console.log(RouterFactory);
const routerFactory = new RouterFactory({
mode: 'history',
scrollBehavior: nativeScrollBehavior,
});
I get the following error on the server:
I20171208-11:36:50.253(-5)? undefined
W20171208-11:36:50.271(-5)? (STDERR) {stuff ...}
W20171208-11:36:50.277(-5)? (STDERR) TypeError: RouterFactory is not a constructor
W20171208-11:36:50.279(-5)? (STDERR) at routerFactory.js (imports/routerFactory.js:7:23)
W20171208-11:36:50.281(-5)? (STDERR) at fileEvaluate (packages\modules-runtime.js:343:9)
W20171208-11:36:50.284(-5)? (STDERR) at require (packages\modules-runtime.js:238:16)
It seems like the import is failing. Is this still the right way to use vue-router in a Meteor app? I noticed the demo app installs vue-router directly from npm. Do we even need to use akryum:vue-router2 anymore?
I see why this won't work: https://github.com/meteor-vue/vue-meteor/blob/master/packages/vue-router2/package.js#L26
Is there any reason to include akryum:vue-router2 in a SSR app then? Or is there is a good way to load it on the client side and not on the server, and have things work properly?
Ended up just using vue-router directly in my CreateApp function:
import './plugins'
import Vue from 'vue'
import VueRouter from 'vue-router'
import routes from './routes'
import App from './ui/App.vue'
function CreateApp () {
const router = new VueRouter({
mode: 'history',
routes,
})
return {
app: new Vue({
el: 'app',
router,
...App,
}),
router
}
}
export default CreateApp
Seems like the only thing this breaks is the foo.routes.js file, but I've just converted that to the standard format instead. Would I be missing anything else?