Hook Menu Deprecated hook_menu alter too

hook_menu is used to create a custom page from your module till drupal 7 version , Now In drupal 8 its changed to yaml based, Basically now you have to create controller, routes.yml and basic info file for your module


1. First you need to create

yourmodulename    folder inside drupal 8 modules folder, then create info file thatis 


name: 'Your Module name'
description: 'Decription'
package: 'If needed'
type: module
core: 8.x

then create yourmodulename.routing.yml

 path: '/anything'
  _controller: '\Drupal\yourmodulename\Controller\CustomController::someMethodInController'
  _title: 'Your custom title'
  _permission: 'any permission you want'

now create controller file 

everything you doing here is inside your module

now create a file inside your module in a path src\Controller\CustomController.php 


 * @file
 * Contains \Drupal\youmodulename\Controller\CartController.

namespace Drupal\youmodulename\Controller;
use Drupal\Core\Controller\ControllerBase;

 * Contains the custom controller.
class CustomController extends ControllerBase
  public function someMethodInController() {
    return array(
          '#type' => 'markup',
          '#markup' => "simply to say hello",


Enable your module and load your page at anything, Thats it