How to get Route Params inside Resolve Angular 2

angular/router navigate with params
angular redirect to route
angular get route path parameters
angular redirect to url
angular multiple resolvers
angular url parameters
when to use angular resolver
angular resolver error handling

I am trying to get my route params inside a resolve. However it doesn't contain the params but when I use activatedRoute from inside a component it does work. I think it's because the route hasn't changed yet inside the resolve. How do I get this to work?


export class PostResolver implements Resolve<any> {
    slug: any;

        private activatedRoute: ActivatedRoute,
        private memoryService: MemoryService,
        ) {}

    resolve() {


        this.activatedRoute.params.subscribe(params => {
            this.slug = params['slug'];
            return this.memoryService.getPost(this.slug);



    path: 'post/:slug',
    component: PostComponent,
    data: {title: 'Post'},
    resolve: {
        post: PostResolver
import { Resolve, ActivatedRouteSnapshot } from '@angular/router';

resolve(route: ActivatedRouteSnapshot) {
    console.log(; // {title: "Post"}

Angular 2 : How to get params on resolve, Your SingleRtoResolve should implements Resolve<T> . Then you'll just need your data service ( RtoService i guess) in your constructor() {} . TypeError: Cannot read property 'params' of undefined. I can't explain why the interface Resolve requires any argument types, but to make it work just add <any> argument type to Resolve. resolve() gets 2 arguments while it's executing, but this.route tries to get the property of this class with name route, which is not correct.

resolve(route: ActivatedRouteSnapshot) {
   console.log(; // "Post"
   console.log(route.params['slug']) // prints the dynamic parameter value

Resolving route data in Angular, We often want to make sure that certain data is available before a component is instantiated via routing. In this article you'll learn how to resolve route data. Angular, we've learned that we can easily access route parameters  Angular 10/9/8 Routing Tutorial – Sending & Getting Routes Parameters Last updated on May 12, 2020 by Digamber In this Angular 10/9/8 Routing tutorial, we will learn how to set parameters to routes along with that we will also look at how to access or get parameters from the route using ActivatedRoute’s snapshot and paramMap method.

resolve(route: ActivatedRouteSnapshot): Observable<any> {
return' ')));

Angular Router: Route Resolvers, Here we return an observable that wraps a string after a delay of 2 seconds. You can get access to the current route parameters in your resolver using the hn.service'; import { Resolve } from '@angular/router'; import  I started learning Angular 2+ a month ago and am familiar with the basic concepts. I have tried to get hands on experience by building small applications to implement all that I have learnt. Now, I am looking forward to hone my skills and improve more on my practical knowledge, for which I need to practice coding challenges.

In-app navigation: routing to views, 2. Display a List · 3. Create a Feature Component · 4. Add Services In a single-​page app, you change what the user sees by showing or hiding To use the Angular router, an app needs to have at least two components so that it can Update the ngOnInit() method to access the ActivatedRoute and track the id parameter:. To handle such scenario angular router allows us to include route parameters, where we can send any dynamic value for a URL segment. How to Pass parameters to Angular Route Defining the Route. We can define parameter by adding forward slash followed colon and a placeholder (id) as shown below

How To Get Route Path Parameters In Non-Routed Angular, As it turns out, getting route path parameter in a non-routed such as route parameters, static data, resolve data, global query params, and the global fragment. 2. Implement workaround based on router navigation events. I'm playing around with angular in my rails app. This is not a single page app, i'm just using angular in a few places. I'm having a hard time getting route params from the uri to use in my resources. For instance, say I'm on the page /users/1/posts/2. How do I get both user_id and id(for post)?

How to Use Resolve in Angular 2 Routes, Resolve is a powerful technique to achieve the best user-experience when browsing between How to Use Resolve in Angular 2 Routes resolve: { transactions: function (Transaction, $stateParams) { return Transaction. Nothing special going on here. However, if this is all new to you, you might want to read our article on routing.. Let’s take a look at the ContactsDetailComponent.This component is responsible of displaying contact data, so it somehow has to get access to a contact object, that matches the id provided in the route URL (hence the :id parameter in the route configuration).

  • god bless you 😊