Complete integration examples for popular frameworks and routing libraries
The CountriesDB widget works seamlessly with all modern frameworks. Here are complete examples for popular frameworks:
Complete React Router v7 example demonstrating widget reload on route navigation. The widget automatically re-scans the DOM when navigating between routes using the `reload: true` option.
This example uses the following configuration:
Install @countriesdb/widget using npm: npm install @countriesdb/widget
Create a .env file with your public key: VITE_COUNTRIESDB_PUBLIC_KEY=YOUR_PUBLIC_KEY
Set window.CountriesDBConfig and import the widget in your route component's useEffect hook.
@countriesdb/widgetComplete Next.js App Router example demonstrating widget reload on page navigation. The widget automatically re-scans the DOM when navigating between pages using the `reload: true` option.
This example uses the following configuration:
Install @countriesdb/widget using npm: npm install @countriesdb/widget
Create a .env.local file with your public key: NEXT_PUBLIC_COUNTRIESDB_PUBLIC_KEY=YOUR_PUBLIC_KEY
Set window.CountriesDBConfig and import the widget in your page component's useEffect hook.
@countriesdb/widgetComplete Vue 3 example with Vue Router demonstrating widget reload on route navigation. The widget automatically re-scans the DOM when navigating between routes using the `reload: true` option.
This example uses the following configuration:
Install @countriesdb/widget using npm: npm install @countriesdb/widget
Create a .env file with your public key: VITE_COUNTRIESDB_PUBLIC_KEY=YOUR_PUBLIC_KEY
Set window.CountriesDBConfig and import the widget in your route component's onMounted hook.
@countriesdb/widgetComplete Angular 21 example with SSR/SSG demonstrating widget reload on route navigation. The widget automatically re-scans the DOM when navigating between routes using the `reload: true` option. Uses `afterNextRender` and `isPlatformBrowser` for SSR compatibility.
This example uses the following configuration:
Install @countriesdb/widget using npm: npm install @countriesdb/widget
Update src/environments/environment.ts with your public key: countriesDbPublicKey: 'YOUR_PUBLIC_KEY'
Set window.CountriesDBConfig and import the widget in your route component using afterNextRender with isPlatformBrowser check.
@countriesdb/widgetComplete SvelteKit example demonstrating widget reload on route navigation. The widget automatically re-scans the DOM when navigating between routes using the `reload: true` option.
This example uses the following configuration:
Install @countriesdb/widget using npm: npm install @countriesdb/widget
Create a .env file with your public key: PUBLIC_COUNTRIESDB_PUBLIC_KEY=YOUR_PUBLIC_KEY
Set window.CountriesDBConfig and import the widget in your route component's onMount hook.
@countriesdb/widget