How to use a contextual 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 contextual filter to limit the list by topic. So, a link to the view might be /books-by-title/34 where 34 is the taxonomy term id for "self-help". The result is a list of self-help books in title order. Works great.

The user may also want to view the same books in popularity order, so I include a menu in the view header, one choice being "By Popularity". The menu link needs to be /books-by-popularity/34.

How do I pass the term id (34) from the URL into the menu link?

Seems like this should be easy, but after reading a dozen articles and trying several approaches, no success.

I should note that a given book be assigned more than one topic. For example, a "self-help" book may also be classified as being about "exercise". So I can't get the term id simply by looking at the topic field of the book.
Something about the answer by @No Sssweat got me thinking, so I searched differently and discovered that arguments.field_topic_target_id contains the value from the contextual filter. So, the answer is to my question is to use:

/books-by-popularity/{{ arguments.field_topic_target_id }}


as the Popularity link in the menu. Credit to @No Sssweat for providing the spark!