![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
@sect/use-placeholder-path
Advanced tools
A custom React hook to retrieve placeholder path in Next.js App Router.
A custom React hook to retrieve placeholder paths in Next.js App Router.
Next.js 13+ App Router doesn't provide a built-in method to return the path of placeholder values, unlike router.pathname
in Pages Router. This hook fills that gap, allowing you to get the placeholder path in the App Router, similar to how you would in the Pages Router.
For developers migrating from Pages Router to App Router, this hook can significantly reduce the pain points associated with the transition. It provides a familiar way to access placeholder paths, making it easier to port existing code and maintain consistency in your application's routing logic. By offering functionality similar to router.pathname
, usePlaceholderPath
helps bridge the gap between the two routing systems, allowing for a smoother migration process and reducing the need for extensive refactoring of route-dependent code.
npm install @sect/use-placeholder-path
# or
yarn add @sect/use-placeholder-path
# or
pnpm add @sect/use-placeholder-path
'use client';
import usePlaceholderPath from '@sect/use-placeholder-path';
const MyComponent = () => {
const placeholderPath = usePlaceholderPath();
return (
<div>
<p>Current placeholder path: {placeholderPath}</p>
</div>
);
}
export default MyComponent;
usePlaceholderPath(options?: UsePlaceholderPathOptions): string
interface UsePlaceholderPathOptions {
optionalCatchAllSegments?: string;
}
optionalCatchAllSegments
: (optional) The name of the optional catch-all segment. If provided, enables handling of top-level optional catch-all segments./users/123/posts/456
/users/[userId]/posts/[postId]
/blog/2024/08/15
/blog/[...slug]
/shop/a/b/c
/shop/[[...slug]]
[!NOTE] For Top-Level Optional Catch-all Segments, special handling may be required. See the "Known Issues" section for more details.
usePlaceholderPath
requires the use of a Client Component.Top-Level Optional Catch-all Segments are expected to return /folderName/[[...segmentName]]
, but currently /folderName
is returned.
/shop/[[...slug]]
/shop
This is due to the technical limitations in detecting Top-Level Optional Catch-all Segments in the Next.js App Router.
To address this limitation, we've introduced an optional configuration:
const placeholderPath = usePlaceholderPath({
optionalCatchAllSegments: 'slug'
});
See CHANGELOG.
✌️
A little project by @sectsect
FAQs
A custom React hook to retrieve placeholder path in Next.js App Router.
We found that @sect/use-placeholder-path demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.