-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
VueRouter beforeRouteEnter hook data changes are not reloaded #64
Comments
I have been running into this issue this week while looking at moving our product to using Any updates or guidance would be appreciated. |
I'm also having this issue where all my routes fetch data in the Will the router hooks be supported by hot-reload or are we left with |
me too |
yeah having the same issue, my workaround atm is while developing set the data in the mounted hook. |
Be cool to get attention on this issue. Guess i have to forgo HMR for now. |
It has been a while and it seems this still is an issue. Any updates on this? |
Workaround for Vue2It will be useful in 95%+ cases when editing a component. // unique for component
let hmrName = 'some-string';
export default {
created() {
if (window[hmrName]) {
Object.assign(this._data, window[hmrName]._data);
}
},
mounted() {
window[hmrName] = this;
},
destroyed() {
delete window[hmrName];
},
} As a mixin with parameters// src/mixins/hmr.js
export function vHmrStateMixin(name) {
// NOTE: use only in DEV
if (!process.env.DEV) {
return {};
}
let store = window._devHmr = window._devHmr || Object.create(null);
return {
created() {
if (store[name]) {
Object.assign(this._data, store[name]._data);
}
},
mounted() {
store[name] = this;
},
destroyed() {
delete store[name];
},
};
} // src/views/Home.vue
export { vHmrStateMixin } from '@/mixins/hmr';
export default {
mixins: [vHmrStateMixin('home')],
beforeRouteEnter(to, from, next) { ... },
} ExplanationHMR executes hooks:
The order of events is important. Saving in the We use |
Hi,
thanks for your work on hot reload!
I'm using vue-hot-reload-api implicitly with webpack dev server and vue-loader. When introducing vue-router into the mix and declaring a beforeRequestEnter hook, hot reloading does not work.
Expected behaviour
Hot reloading should reload data set by vue-routers beforeRequestEnter hook as well.
Actual behaviour
The beforeRequestEnter hook is executed, but the data set on the instance is not reloaded.
Steps to reproduce
Clone https://github.com/stoically/vue-router-hot-reload-issue (based on
vue init webpack-simple
)npm install
npm run dev
Navigate to http://localhost:8080
You'll see
Message from VueRouter: beforeRouteEnter
Now make a change in the
src/Router.vue
fileMessage changes to
Message from VueRouter: data
Notes
I'm actually not sure if this is expected behaviour. But if it is I would appreciate any pointers on how to achieve hot reloading in this case manually.
Best regards
The text was updated successfully, but these errors were encountered: