Skip to content

Latest commit

 

History

History
119 lines (87 loc) · 2.26 KB

RouterService.md

File metadata and controls

119 lines (87 loc) · 2.26 KB

API: RouterService

See also: Examples RouterService


Access through injection:

import { inject, withInject, RouterService } from '@mercedes-benz/ftk-core';
// ...
class Example extends React.Component<{}, {}> {
  @inject()
  public router!: RouterService;
  // ...
}

export default withInject(Example);

Access through hook

import { useRouter } from '@mercedes-benz/ftk-core';
// ...
const router = useRouter();
// ...


getRoute()

getRoute(): {
    name: string;
    url: string;
    parameter: any;
    query: any;
}: IRoute;

The getRoute Method provides the current route and an easy way to access the route- and query-params.


linkTo()

linkTo(
    name: string,
    parameter?: object,
    query?: object
): string;

The linkTo Method provides the URL of a route, specified by its parameters.


linkToHome()

linkToHome(): string;

The linkToHome Method provides the URL of the Home-route.


navigate()

navigate(url: string): void;

The navigate Method navigates to a given URL.


navigateToHome()

navigateToHome(): void;

The navigateToHome Method navigates to the Home-route.


Not implemented yet: navigateTo()

navigateTo(
  name: string,
  parameter?: object,
  query?: object
): void;

TODO: 🔧 Implement a method, that navigates directly to a route, specified by its parameters.



Navigation within Swidgets

When using Swidgets, the router takes care of nested routing. So a route-change within the Swidget will also change the route of the host-application. This also works with multiple Swidgets, that are loaded at the same time, as long as:

  • you provide a unique ID for each Swidget
  • the unique ID is not random (and stays the same when reloading the host-application)