# How to suppress hyperlinks for custom headers in toc but still keep hyperlink for entries and page numbers?

I would like to use hyperlinks for page numbers and the appropriate entries in my table of contents, which works great using \usepackage[linktoc=all]{hyperref} for me. Only problem I have is, that I am trying to divide my entries into different "sections" which represent headers using the tocloft package and \cftaddtitleline. Each section can contain multiple entries like this:

For some reason, my headers have a hyperlink aswell which is not desired. I would like to have the hyperlinks only for entries and page numbers, not for the headers. Now I know I can suppress the hyperlink for the headers using \usepackage[linktocpage=true]{hyperref}, but this removes my hyperlinks for the entries aswell. This is not desired, "First entry", "Second entry" and "0.1 Third Entry" should still have a hyperlink.

This is the desired output, which I was not able to recreate in LaTeX:

Here's my code. For reusage you will have to create a folder named "folder" containing two different pdf-files named "file1.pdf" and "file2.pdf" in the local directory where your tex-file is stored. Or you can of course just use \section instead of \includepdf (and of course remove the appropriate arguments).

\documentclass{scrreprt} % notice this is a KOMA-script class

\usepackage{pdfpages}
\usepackage{tocloft}

\begin{document}

% Dummy Page
\chapter*{Dummy Page}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a diam lectus.

\clearpage
\tableofcontents

% Assign the TOC entries to different sections of TOC
\cftaddtitleline{toc}{part}{First section of table of content}{}

\cftaddtitleline{toc}{part}{Second section of table of content}{}

\section{Third entry}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a diam lectus.

\end{document}


Thanks for any help in advance!

I was able to solve my problem based on this answer here: https://tex.stackexchange.com/a/301490/206040

This is the new complete code using \addtocontents and \contentsline before hyperref transforms them to make hyperlinks possible. For the headers I've created a new command called \tocheader which can be given the header name as an argument. Also this solution does not require the usage of the tocloft package anymore.

\documentclass{scrreprt} % notice this is a KOMA-script class

\usepackage{pdfpages}

\let\origcontentsline\contentsline

\begin{document}

% Dummy Page
\chapter*{Dummy Page}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a diam lectus.

\clearpage
\tableofcontents

% Assign the TOC entries to different sections of TOC
\tocheader{First section of table of content}