How do I convert hook_menu()? I am having site built in Drupal 7 and in future I want to migrate my site to Drupal 8.

How can I write hook_menu() and hook_menu_alter() to routing.yml files?
Here is an example taken from All functionality of hook_menu() is replaced by new systems for routing, menu links, local tasks, actions and contextual links:

Drupal 7

in modules/book/book.module:

function book_menu() {
   $items['book/export/%/%'] = array(
    'page callback' =&gt; 'book_export', 
    'page arguments' =&gt; array(2, 3), 
    'access arguments' =&gt; array('access printer-friendly version'), 
    'type' =&gt; MENU_CALLBACK, 
    'file' =&gt; 'book.pages.inc',
  );
    $items['node/%node/outline'] = array(
    'title' =&gt; 'Outline', 
    'page callback' =&gt; 'book_outline', 
    'page arguments' =&gt; array(1), 
    'access callback' =&gt; '_book_outline_access', 
    'access arguments' =&gt; array(1), 
    'type' =&gt; MENU_LOCAL_TASK, 
    'weight' =&gt; 2, 
    'file' =&gt; 'book.pages.inc',
  );
...
  return $items;
}


Drupal 8

in modules/book/book.routing.yml:

book_export:
  pattern: '/book/export/{type}/{node}'
  defaults:
    # What's being returned is the entire response (not HTML, or even if HTML, we don't want additional blocks around it), so use _controller instead of _content.
    _controller: '\Drupal\book\BookController::export'
  requirements:
    _permission: 'access printer-friendly version'
book_node_outline:
  pattern: '/node/{node}/outline'
  defaults:
    _controller: '\Drupal\book\BookController::outline'
  requirements:
    # Indicates that the book outline access access system should be invoked.
    _book_outline_access: TRUE