![](https://private-user-images.githubusercontent.com/33983644/255353467-728745c5-0dbd-47f7-a4d1-d28fd897cdfb.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjEzNDAyNzEsIm5iZiI6MTcyMTMzOTk3MSwicGF0aCI6Ii8zMzk4MzY0NC8yNTUzNTM0NjctNzI4NzQ1YzUtMGRiZC00N2Y3LWE0ZDEtZDI4ZmQ4OTdjZGZiLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA3MTglMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNzE4VDIxNTkzMVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWU4MGI0ZDBlNzE2ZDk2YzU4YzlhOTg2NzA5YjBmM2I0MWE1MjExMGQ3ZDEwYmNiMWY5MWMyYjE4ZjA5NmI0M2MmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.1VnDs402nLSZptuHCCbH89N0LPYxEuI4_tzobtFue08)
Astro Out Proxy is a JavaScript library that enhances the user experience by providing a warning prompt before they leave the website upon clicking an external link. This feature helps prevent accidental navigation away from the current page and gives users the opportunity to confirm their action.
Demo url: https://astro-out-proxy.vercel.app/
In some cases (E-commerce, government, banking apps) you want or are obliged to warn the user before they leave your site. And astro-out-proxy helps you do that.
- Warns users before they navigate to an external website from your application.
- Customizable warning message to suit your application's needs.
- Lightweight and easy to integrate into any project.
You can install astro-out-proxy
with astro-add or manually
pnpm astro add astro-out-proxy
pnpm add astro-out-proxy
And then in your astro.config.mjs
add the basic config:
import { defineConfig } from "astro/config";
import outProxy from "astro-out-proxy";
// https://astro.build/config
export default defineConfig({
// ...
integrations: [outProxy()],
});
IMPORTANT as of now only pages/out.astro
is supported, hang on tight for updates!
Create pages/out.astro
with the code below. The library comes with a simple design out of the box. If you want to use your own styles you can do that by wrapping it with the <OutPage />
component and setting the customUi
attribute. Make sure to add the id leaveButton
to your leave button to use the script that fills out the href for it. Or you can create your own logic!
---
import OutPage from "astro-out-proxy/components/OutPage";
---
<!-- Default UI -->
<OutPage />
<!-- Custom UI - you must add the customUi parameter for this to work!-->
<OutPage customUi>
<a id="leaveButton">Leave</a>
</OutPage>
If you installed via astro-add or added the integration in the astro config file manually, the build step is already configured. The integration will automatically change re-write the links for you.
To use the package during development you will have to add the OutLinkDevModeComponent
to your project. Make sure to place it in a place so that it is on every page - preferably in the head - as in demo/src/layouts/BaseLayout.astro
---
import OutLinkDevModeComponent from "astro-out-proxy/components/OutLinkDevModeComponent";
---
<html lang="en">
<head>
<OutLinkDevModeComponent />
...
With the integration options you can control the behaviour of the integration during build-time.
IMPORTANT more options are on the way
safeAttribute
: The external links with this attribute won't be routed through the proxy. Default value:data-safe
// astro.config.mjs
export default defineConfig({
integrations: [outProxy({
safeAttribute: "data-noproxy"
})],
})
redirectParameter
: The parameter used in the redirection URL which will contain the URL of the external site. Default value:redirect
// astro.config.mjs
export default defineConfig({
integrations: [outProxy({
redirectParameter: "customParam"
})],
})
This will generate the following example:
https://website.domain/out?
customParam
=https%3A%2F%2Fwww.google.com&target=&rel=
Then, pass this custom parameter into the OutPage component like bellow:
<OutPage options={{redirectParameter: "customParam"}} />
You can achieve the same result by using the OutLinkDevModeComponent:
<OutLinkDevModeComponent options={{redirectParameter: "customParam"}} />
Contributions to Astro Out Proxy are welcome! If you find any issues or want to suggest improvements, please open an issue or submit a pull request on the project's GitHub repository.
Astro Out Proxy is licensed under the MIT License. Feel free to use, modify, and distribute the library as per the terms of the license.