For navigation, whether I am using an embed method or the template partials with Stash approach, I find it easier to pass a parameter specifying which section I want active rather than trying to detect it manually.
In my experience there is always an edge case requiring a more manual / granular approach that will defeat any automatic setup down the road.
Embeds
In main template
{embed="embeds/.header" active_nav="articles"}
In embedded template
<ul>
<li><a{if embed:active_nav == "articles"} class="active"{/if} href="{site_url}articles/">Articles</a></li>
<li><a{if embed:active_nav == "news"} class="active"{/if} href="{site_url}news/">News</a></li>
...
</ul>
template partials
In partial template
{embed="layouts/.main"}
{exp:stash:set_value name="active_nav" value="articles"}
In layout (.main) template
<ul>
<li><a{if "{exp:stash:get name='active_nav'}" == "articles"} class="active"{/if} href="{site_url}articles/">Articles</a></li>
<li><a{if "{exp:stash:get name='active_nav'}" == "news"} class="active"{/if} href="{site_url}news/">News</a></li>
...
</ul>
Variant with body class only
In partial template
{embed="layouts/.main"}
{exp:stash:set_value name="body_class" value="body_articles"}
In layout template
<body{if {exp:stash:not_empty name="body_class"}} class="{exp:stash:get name='body_class'}"{/if}>
<ul>
<li class="articles"><a href="{site_url}articles/">Articles</a></li>
<li class="news"><a href="{site_url}news/">News</a></li>
...
</ul>
in your CSS
.body_articles .articles > a
{
do something
}
From the two add-ons mentioned by Anna, I would go down the switchee route
{exp:switchee variable="{segment_2}" parse="inward"}
{case value="#^P(\\d+)$#|''"}
code if pagination page
{/case}
{case default="Yes"}
code if not a pagination page
{/case}
{/exp:switchee}
The advantage of switchee beeing that, if you have channel entries loops or anything heavy process-wise, it only get executed should the tested condition apply. Better for performance.