Where you implemented hook_menu()
, in Drupal 8 you need:
A .routing.yml file containing the routing definition
example.name:
path: '/example/{variable}'
defaults:
_controller: '\Drupal\example\Controller\ExampleController::content'
requirements:
_permission: 'access content'
A controller class for the page callback
class ExampleController {
// ...
public function content($variable) {
// Do something with $variable.
}
}
What is important is the file structure, which should be as follows, assuming that example is the machine name of the module.
Keep in mind that you can change the machine name of the module, the route name (example.name), and the name of the class implementing the controller (ExampleController); the ones I used are only examples.