Skip to content

Instantly share code, notes, and snippets.

@maecha
Last active June 29, 2018 01:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maecha/55832779493740db373f1efe1a2aae29 to your computer and use it in GitHub Desktop.
Save maecha/55832779493740db373f1efe1a2aae29 to your computer and use it in GitHub Desktop.
Get the name of controller, from JS
getControllerName() {
// Ex) DOMAIN.com/NAME_SPACE/CONTROLLER_NAME/ACTION
var pathname = window.location.pathname; // /NAME_SPACE/CONTROLLER_NAME/ACTION
let splitedPathnames = pathname.replace(/\//, ''); // [ 'NAME_SPACE', 'CONTROLLER_NAME', 'ACTION' ]
return splitedPathnames.split('/')[1]; // CONTROLLER_NAME
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment