See also: Examples RouterService
- Access through injection:
- Access through hook
- getRoute()
- linkTo()
- linkToHome()
- navigate()
- navigateToHome()
- Not implemented yet: navigateTo()
- Navigation within Swidgets
import { inject, withInject, RouterService } from '@mercedes-benz/ftk-core';
// ...
class Example extends React.Component<{}, {}> {
@inject()
public router!: RouterService;
// ...
}
export default withInject(Example);
import { useRouter } from '@mercedes-benz/ftk-core';
// ...
const router = useRouter();
// ...
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(
name: string,
parameter?: object,
query?: object
): string;
The linkTo Method provides the URL of a route, specified by its parameters.
linkToHome(): string;
The linkToHome Method provides the URL of the Home-route.
navigate(url: string): void;
The navigate Method navigates to a given URL.
navigateToHome(): void;
The navigateToHome Method navigates to the Home-route.
navigateTo(
name: string,
parameter?: object,
query?: object
): void;
TODO: 🔧 Implement a method, that navigates directly to a route, specified by its parameters.
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)