Ember.js V5 - App Controller Router Props

This codemod replaces all occurrences of this.currentRouteName with this.router.currentRouteName and this.currentPath with this.router.currentPath.

Ember.js
jscodeshift
Estimated time saving
5 minutes/occurrence
Change mode
Autonomous
Applicability criteria

Ember.js version higher or equal to 3.10.

Made by
Rajasegar Chandran
Rajasegar Chandran

Usage →

Codemod CLI:

intalling vs code extension tooltip icon
codemod ember/5/app-controller-router-props
copy CLI command icon

Codemod VS Code extension:

intalling vs code extension tooltip icon
vs code logo
Run in VS Code

Use/edit codemod in Codemod Studio:

intuita logo without text
Open in Codemod Studio

Description

This codemod replaces all occurrences of this.currentRouteName with this.router.currentRouteName and this.currentPath with this.router.currentPath.

Example

Before:

import Controller from '@ember/controller';
import fetch from 'fetch';

export default Controller.extend({
	store: service('store'),

	actions: {
		sendPayload() {
			fetch('/endpoint', {
				method: 'POST',
				body: JSON.stringify({
					route: this.currentRouteName,
				}),
			});
		},
	},
});

After:

import Controller from '@ember/controller';
import fetch from 'fetch';

export default Controller.extend({
	router: service('router'),
	store: service('store'),

	actions: {
		sendPayload() {
			fetch('/endpoint', {
				method: 'POST',
				body: JSON.stringify({
					route: this.router.currentRouteName,
				}),
			});
		},
	},
});