views – How to use a context filter value in a menu displayed on the same page

I use a view to display a list of books sorted by title. The view has a context filter to limit the list by subject. So a link to the view could be / books by title / 34 where 34 is the id taxonomy term for "self-help". The result is a list of self-help books in the order of titles. Works very well.

The user may also want to display the same books in order of popularity. I therefore included a menu block in the header of the view, one of the choices being "By popularity". The menu link must be / books-by-popularity / 34.

How to pass the term id of the URL in the menu link?

Looks like it should be easy, but after reading a dozen articles and tried several approaches, no success.