Beacon API Docs
  • Beacon - Installation
  • Beacon - Usage
    • Beacon Usage - Overview
    • Usage in a Next.js Environment
    • Open and Close Programmatically
  • Native Routing in Beacon
    • Vanilla JS - Native Routing Example
    • React JS - Native Routing Example
    • Vue JS - Native Routing Example
    • Angular JS - Native Routing Example
  • Loading User Data into BeaconBar
  • Loading Session Data into Beacon Bar
  • Callbacks in Beacon
    • Add Callbacks in Beacon
    • Remove Callbacks in Beacon
    • React Example for Callbacks
  • Trigger smart journeys From Your App
  • Execute Command From Your App
  • Open Help Docs From Your App
  • Emitting Events to Beacon
  • Listening to events from Beacon Bar
    • Adding event listeners in Beacon
    • Removing event listeners in Beacon
    • React Example for Event Listeners in Beacon
  • List of events emitted by Beacon Bar
  • Implementing Content Security Policy (CSP) for Beacon Integration
Powered by GitBook
On this page
  1. Native Routing in Beacon

Angular JS - Native Routing Example

Enabling Native Routing with @beacon.li/bar in an Angular Component

If you're using Angular and the Angular Router and you want to enable native routing for the Beacon widget, you can achieve this by integrating the @beacon.li/bar package with your Angular component. This allows you to control the behavior of the Beacon widget based on the current route using the OnInit lifecycle hook.

Integrating @beacon.li/bar with Angular Router

Here's how you can enable native routing with Beacon in your Angular component:

  1. Import the necessary modules and components at the beginning of your component:

import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { Beacon } from '@beacon.li/bar';
  1. Create your Angular component as usual and implement the OnInit interface:

@Component({
    selector: 'app-my-component',
    templateUrl: './my-component.component.html',
    styleUrls: ['./my-component.component.css']
})
export class MyComponent implements OnInit {
  1. Inject the Angular Router service into your component's constructor:

constructor(private router: Router) {
}
  1. Use the ngOnInit lifecycle hook to set up Beacon's router based on the current route. This allows you to navigate to different routes when the user interacts with the Beacon widget:

ngOnInit() {
    Beacon.setRouter((path: string) => {
        this.router.navigateByUrl(path);
    });
}

How It Works

  • The Router service from the Angular Router provides you with methods for navigating to different routes in your Angular application.

  • In the ngOnInit method, you call Beacon.setRouter((path: string) => this.router.navigateByUrl(path)). This configures Beacon to use the Angular Router's navigateByUrl method when navigating to different routes.

  • Whenever the user interacts with the Beacon widget, it will trigger this router configuration, allowing you to seamlessly integrate beacon into your Angular application's navigation flow.

By following these steps, you can enable native routing for the Beacon widget in your Angular component, ensuring a consistent and user-friendly experience when users interact with the beacon bar.

PreviousVue JS - Native Routing ExampleNextLoading User Data into BeaconBar

Last updated 1 year ago