Cannot access this.$route in Vue class constructor with Vue-Router >= 2.6.0

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


Cannot access this.$route in Vue class constructor with Vue-Router >= 2.6.0



I upgraded our Vue project to the latest versions of its packages, including Vue-Router from 2.5.3 to 2.7.0. Suddenly several of our modules have stopped working because we can no longer access this.$route in the constructor.


@Component({
template,
name: 'Something'
})
export class Something extends Vue {
someParam: string;
constructor() {
super();
// Works in Vue-Router 2.5.3, not in >= 2.6.0, get a null ref exception
this.someParam = this.$route.params.someParam;
}
}



I started moving what I can to Vue's beforeCreate() lifecycle hook, but these assignments are all over the project. What changed in vue-router that broke this? (or was this never supposed to work in the first place?)



Is there an easier way to fix this than scouring through the project moving all these assignments from the constructor to beforeCreate()? For that matter, what would be considered the best practice for this anyway?





What version of vue-class-component do you use?
– imcvampire
Sep 22 '17 at 14:27


vue-class-component




1 Answer
1



Usage this.$parent.$route.params






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Arduino Mega cannot recieve any sketches, stk500_recv() programmer is not responding

Visual Studio Code: How to configure includePath for better IntelliSense results

C++ virtual function: Base class function is called instead of derived