I have encountered a problem in latex that I have not been able to solve. While the hyperref package generates clickable links in the table of contents, it does not link any subsection to the actual subsection but to the section that they are under. Is there anyway to change this behaviour so that it either links to the subsection itself or the page the subsection is on?

After looking into it a bit more, it seems that it is required that one disables section numbering and uses the titlesec package for this issue to show. Below is a sample of this issue:

\documentclass{report}
\setcounter{secnumdepth}{0}
\usepackage{titlesec}
\hypersetup{
citecolor=black,
filecolor=black,
urlcolor=black
}

\begin{document}
\tableofcontents
\chapter{test}

Test text
\newpage
\section{A section}

Lorem Ipsum
\newpage

\end{document}

-
Thank you for adding the MWE. –  Gonzalo Medina Sep 2 '12 at 2:12
The message Package hyperref Warning: The anchor of a bookmark and its parent's must not be the same. Added a new anchor on input line 20. gives you a hint to the anchor. The answer by Gonzalo Medina explains why. –  Kurt Sep 2 '12 at 2:20
titlesec is not compatible with hyperref for unnumbered sections, see README of hyperref. –  Heiko Oberdiek Sep 2 '12 at 5:39

Since you are setting secnumdepth to zero, no anchors are generated for the hyperlinks and this produces the undesired effect mentioned; the following code works as expected:

\documentclass{report}
\usepackage{titlesec}
\hypersetup{
citecolor=black,
filecolor=black,
urlcolor=black
}

\begin{document}
\tableofcontents
\chapter{test}

Test text
\newpage
\section{A section}

Lorem Ipsum
\newpage

\end{document}


If you want to have all your sections and subsections to be unnumbered but included in the ToC and stll generating the correct hyperlinks, one option would be to use the \phantomsection command to generate the anchors:

\documentclass{report}
\setcounter{secnumdepth}{0}
\usepackage{titlesec}
\hypersetup{
citecolor=black,
filecolor=black,
urlcolor=black
}

\begin{document}
\tableofcontents
\chapter{test}

Test text
\newpage
\phantomsection
\section{A section}

Lorem Ipsum
\newpage
\phantomsection

\end{document}


Another option would be to use the titlesec and titletoc packages to remove the numbering from both the document body and the ToC:

\documentclass{report}
\usepackage{titlesec}
\usepackage{titletoc}

\titleformat{\section}
{\normalfont\Large\bfseries}{}{1em}{}
\titleformat{\subsection}
{\normalfont\large\bfseries}{}{1em}{}
\titlecontents{section}
[1.5em] {}{}{}
{\titlerule*[1em]{.}\contentspage}
\titlecontents{subsection}
[3.8em] {}{}{}
{\titlerule*[1em]{.}\contentspage}

\hypersetup{
citecolor=black,
filecolor=black,
urlcolor=black
}

\begin{document}
\tableofcontents
\chapter{test}

Test text
\newpage
\section{A section}

Lorem Ipsum
\newpage

\end{document}


Yet another option would be to use the starred versions of the sectional units (i.e., \section*, \subsection*) and to use \addcontentsline to manually add the entries to the ToC:

\documentclass{report}

\hypersetup{
citecolor=black,
filecolor=black,
urlcolor=black
}

\begin{document}
\tableofcontents
\chapter{test}

Test text
\newpage
\section*{A section}