Checking pathname and add an specific index
Unanswered
Kintamani posted this in #help-forum
KintamaniOP
I need to add tabindex 0 if path is this /admin/project-areas/parks/benchmark/2024/10/questionnaire
20 Replies
@@ts-ignore https://nextjs.org/docs/app/api-reference/functions/use-pathname
KintamaniOP
how to get last segment or just give me example of adding an active state
I'm stuck cant think a way
@Kintamani I'm stuck cant think a way
the
usePathname will give you full pathname, just check if pathname equals to your url and add tabindexKintamaniOP
hey
<Link className={'link'} href={
<SectionNavigationItem active={pathname === '/admin/project-areas/parks/benchmark/2024/10/questionnaire' && true } title={'Questionnaire'} />
</Link>
/admin/project-areas/parks/benchmark/2024/10/questionnaire}><SectionNavigationItem active={pathname === '/admin/project-areas/parks/benchmark/2024/10/questionnaire' && true } title={'Questionnaire'} />
</Link>
is this a good way?
KintamaniOP
ok
thanks
I have a problem here
/admin/project-areas/parks/benchmark/2024/10/questionnaire in this pathname active state should be true and if there's another pathname/admin/project-areas/parks/benchmark/2024/10/questionnaire/report
then also it should be positive
how to do that
?
ur my saviour
KintamaniOP
please when ur online drop an message
you can use a regex or just do string.startsWith
KintamaniOP
do u know any exapmle
i can check