0.1.10 • Published 8 months ago

next-url-parent v0.1.10

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

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~

0.1.11-b3

8 months ago

0.1.11-b2

8 months ago

0.1.11-b1

8 months ago

0.1.11-b0

8 months ago

0.1.11-b5

8 months ago

0.1.11-b4

8 months ago

0.1.10

1 year ago

0.1.9

1 year ago

0.1.8

1 year ago

0.1.7

1 year ago

0.1.6

1 year ago

0.1.5

1 year ago

0.1.4

1 year ago

0.1.3

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago

0.1.0

1 year ago