You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

next-url-parent

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

next-url-parent

A simple package to get the parent URL of the current URL in Next.js APP router.

0.1.10
latest
Source
npmnpm
Version published
Weekly downloads
0
-100%
Maintainers
1
Weekly downloads
 
Created
Source

next-url-parent

Project starts on 30-03-2024

MIT License   Donation

npm version npm downloads

Get the parent URL of the current URL in Next.js APP router.

📦 Requirements

  • A Next.js project using app router.

🚀 Getting Started

Installation

npm install next-url-parent

Visit the npm page.

Setup package.json

Add the following code to package.json:

"scripts": {
 // other scripts ...
 "mup@gen": "next-url-parent"
 "mup@watch": "next-url-parent --watch"
 },

Read 💻 CLI for more details.

Usage 🎉

[!NOTE]
You must run the next-url-parent command once to get the function and hook working.

Function

import { getParentUrl } from "next-url-parent";

console.log(getParentUrl("https://example.com/parent/child"));
// -> "https://example.com/parent"

console.log(getParentUrl("https://example.com/parent/child?key1=value1&key2=value2", { 
  keepQueryString = true,
  queryStringWhitelist = ["key1"],
}));
// -> "https://example.com/parent?key1=value1"

console.log(getParentUrl("https://example.com/parent/child?key1=value1&key2=value2", { 
  keepQueryString = true,
  queryStringBlacklist = ["key1"],
}));
// -> "https://example.com/parent?key2=value2"
Options
OptionOptionalTypeDefaultDescription
url:x:stringThe child URL.
keepQueryStringbooleanfalseKeep the child URL query string.
queryStringWhiteliststring[][]Whitelist of query string keys.
queryStringBlackliststring[][]Blacklist of query string keys.

Hook

import { useUrlParent } from "next-url-parent";

const MyPage = () => {
  const parentUrl = useUrlParent();

  // Default Options
  const parentUrl = useUrlParent(options: { 
    keepQueryString = false,
    queryStringWhitelist = [],
    queryStringBlacklist = [],
    defaultParentUrl = "",
  });

  return (
    <div>
      <h1>Parent URL: {parentUrl}</h1>
    </div>
  );
};

Options
OptionOptionalTypeDefaultDescription
keepQueryStringbooleanfalseKeep the child URL query string.
queryStringWhiteliststring[][]Whitelist of query string keys.
queryStringBlackliststring[][]Blacklist of query string keys.
defaultParentUrlstring""Default parent URL before the parent URL is resolved.

💻 CLI

next-url-parent --appDir=./src/app --watch

Generate a path map.

OptionOptionalTypeDefaultDescription
--appDir / -istring./src/appThe directory of the Next.js app.
--watch / -wbooleanfalseWatch the files and obfuscate on change.

⭐ TODO

  • Tests

🐛 Known Issues

  • \

🤝 Contributing

Contributions are welcome! If you find a bug or have a feature request, please open an issue.

📝 License

This project is licensed under the MIT License - see the LICENSE file for details

☕ Donation

Love it? Consider a donation to support my work.

"Donation" <- click me~

Keywords

nextjs

FAQs

Package last updated on 02 Apr 2024

Did you know?

Socket

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.

Install

Related posts