eLabSDK2.Router

Hierarchy

  • default

    Router

Methods

getCurrentRoute

Static getCurrentRoute(): string

Get the current application route path.

This retrieves the full path of the currently active route in Vue-based applications (e.g., inventory browser, new journal interface). Returns the complete URL path including hash, query parameters, and path segments. Use this to determine the current page context, implement conditional logic based on location, or track user navigation.

Note: This only works in Vue applications with a router. Returns empty string in legacy pages or applications without a router.

Returns

string

The full path of the current route (e.g., '/inventory/#/sample/123'), or empty string if router is not available.

Example

// Get and display current route
const currentRoute = eLabSDK2.Router.getCurrentRoute();
console.log(`Current route: ${currentRoute}`);

Example

// Conditional logic based on current route
const route = eLabSDK2.Router.getCurrentRoute();
if (route.includes('/inventory/sample/')) {
  enableSampleSpecificFeatures();
} else if (route.includes('/inventory/equipment/')) {
  enableEquipmentSpecificFeatures();
}

Example

// Check if user is on a specific page
function isOnInventoryPage() {
  const route = eLabSDK2.Router.getCurrentRoute();
  return route.startsWith('/members/inventory-rebuild/');
}

Example

// Track current page
eLabSDK2.Router.onSwitchedRoute(() => {
  const route = eLabSDK2.Router.getCurrentRoute();
  trackPageView(route);
}, 'track-pages');

onSwitchedRoute

Static onSwitchedRoute(callback, id): void

Register a callback to execute when the application route changes.

This event fires whenever the user navigates to a different route within a Vue-based application (e.g., inventory browser, new journal interface). The callback receives a CustomEvent with details about the route change. Use this to track navigation, update UI state based on the current route, or perform cleanup when leaving certain pages.

Note: This only works in Vue applications with a router. Will not fire in legacy pages.

Parameters

NameTypeDescription
callback(event: CustomEvent<any>) => voidFunction to execute when the route switches. Receives a CustomEvent with route information.
idstringUnique identifier for this callback registration.

Returns

void

Example

// Track route changes
eLabSDK2.Router.onSwitchedRoute((event) => {
  const newRoute = eLabSDK2.Router.getCurrentRoute();
  console.log(`Navigated to: ${newRoute}`);
  trackAnalytics('route_change', { route: newRoute });
}, 'track-navigation');

Example

// Update UI based on route
eLabSDK2.Router.onSwitchedRoute(() => {
  const currentRoute = eLabSDK2.Router.getCurrentRoute();
  if (currentRoute.includes('/inventory/')) {
    showInventoryTools();
  } else if (currentRoute.includes('/journal/')) {
    showJournalTools();
  }
}, 'update-ui');

Example

// Cleanup on route change
eLabSDK2.Router.onSwitchedRoute(() => {
  clearCustomEventListeners();
  resetTemporaryState();
}, 'cleanup-on-route-change');

© 2023 eLabNext