Hello i would like to create routes with language in this format:
www.domain.com/lang/sometimes
Example:
www.domain.com/en/sometimes
www.domain.com/de/sometimes
Is it possible write to route something like:
RouterModule.forChild({
path: ':lang/sometimes', component: TestComponent
})
Is it possible? How to set to url default language? For example when app starting, set dynamically lang parameter to url.
Thank you for your advices
The Angular router's navigation guards allow to grant or remove access to certain parts of the navigation. Another route guard, the CanDeactivate guard, even allows you to prevent a user from accidentally leaving a component with unsaved changes.
Add a default routelink To make the application navigate to the dashboard automatically, add the following route to the routes array. content_copy { path: '', redirectTo: '/dashboard', pathMatch: 'full' }, This route redirects a URL that fully matches the empty path to the route whose path is '/dashboard' .
Router service needs to be explicitly provided in angular module to use it in another component via DI. You can chain multiple pipe in a single expression along with “async” pipe.
We can test routing in Angular by using RouterTestingModule instead of RouterModule to provide our routes. This uses a spy implementation of Location which doesn't trigger a request for a new URL but does let us know the target URL which we can use in our test specs.
You can do something like this then. You can create two routes, one for default route and another for other Routes.
RouterModule.forChild([
{ path: 'english/users/sometimes', component: UserComponent, useAsDefault: true },
{ path: ':lang/users/sometimes', component: UserCOmponent }
])
Added: For subscribing to the param:
import { ActivatedRoute } from '@angular/router';
constructior(private route: ActivatedRoute)
ngOnInit(){
this.route.params.subscribe(value => {
let lang = value['lang']);
console.log(lang);
});
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With