After last update my site was crashed. Route '/api/menu_items/main' responded with 500 error.
UnexpectedValueException: External URLs do not have an internal route name. in Drupal\Core\Url->getRouteName() (line 555 of /var/www/html/web/core/lib/Drupal/Core/Url.php).
Unrouted links are useful for headless sites - you can place into menu internal link to pages that generated on frontend only.
Source of problem is here /rest_menu_items/src/Plugin/rest/resource/RestMenuItemsResource.php at line 261
if (!$url->isExternal() && $url->getRouteName() === '<nolink>' && in_array($key, $itemsToRemoveWhenNoLink)) {
I suppose, we should also add here one more condition: $url->isRouted()
Comments
Comment #2
gun_dose commentedAnd here is patch to fix this.
Comment #3
andysipple commentedRan into the same problem, reverted back to 2.5 for the time being. I am thinking it was because we had a couple menu links using # at the end of an internal link. Example /some-internal-link#hello-world
I'll try the patch and report back.
Comment #4
gun_dose commentedComment #5
supermoos commentedHaving the same problem.
Comment #6
ainarend commentedCan confirm that the patch in #2 resolves the issue.
But there are two small improvements we can make to the patch:
In there we are calling the $url object to check if the url is not external and whether it's routed. But both of those calls are already stored to a variable.
Drupal\rest_menu_items\Plugin\rest\resource\RestMenuItemsResource:
So we could simply do
________
Other than that, the bug causes a WSOD, but this patch fixes it.
Comment #7
ainarend commentedHere is a new patch with the mentioned small improvements.
Comment #9
ainarend commentedAdding screenshots that show that the patch fixes the 500 error.
Created an unrouted menu item:

500 error on rest menu items api route for main menu:

The same route with the last patch:

____
Okay, in the mean time the testbot has finished and found a coding standard issue.
The test failure was introduced in #3025723 with this commit:
https://git.drupalcode.org/project/rest_menu_items/commit/c4b09e4
Uploaded a new patch with the CS fix.
Comment #11
ainarend commentedOops, missed 1 additional CS issue. Should be all good now.
Comment #13
ainarend commentedOk, don't get it why the testbot says that the patch failed testing now - build is successful and no CS errors. Maybe because of the module doesn't have tests?
Either way, I manually tested the solution and it fixes the issue.
Comment #14
fabianderijkThanks for the patch, I'll add it in the upcoming days
Comment #16
fabianderijkThe patch has been applied and will be available in the dev release. The 8.x-2.8 release will be available soon.