0

I was using the ngrx/router in my app and I wanted to revert back to or replace this to the Component Router. I've noticed that both modules have a 'Router' object and where I had included Router like so:

import {
    Router
} from '@ngrx/router';

I now have:

import {
    Router
} from '@angular/router';

Other items I have extracted here and there but I get two main errors and I was wondering if any one can provide alternative methods or provide a solution to the two errors I have... the first error is

Property 'map' does not exist on type 'Router'.

as the previous Router was an obeserable so I do a lof of things like such:

router
.map((locationChange:LocationChange):boolean => {
     // do something...
    return locationChange.path === '';
 })

The second issue is that the Angular Component Router has no path() method for returning the current URL... does anyone know the way of doing this in the Angular Component Router. I'm currently looking through the documentation and trying to find an article on how to make the switch.

Many thanks in advance.

Mark Sandman
  • 3,293
  • 12
  • 40
  • 60
  • Are you using the package bundler SystemJS, and have you properly setup the angular 2 router module? Have you properly loaded the angular 2 router module in package.json? See the Quick start systemjs.config.js that is provided by the Angular.io install guide: https://github.com/JaimeStill/ng2Quickstart/blob/master/systemjs.config.js – Jaime Still Jul 29 '16 at 10:36
  • I am using SystemJS but I forgot to set that up. I have updates the package.json... I will check out the link now! – Mark Sandman Jul 29 '16 at 11:05

1 Answers1

0

If you are using Visual Studio 2015 then there is a known bug with the TS.

See this link. You have to replace a typescript services js file with a different one than is installed until the problem is fixed.

https://github.com/Microsoft/TypeScript/issues/8518#issuecomment-229506507

As far as your path question. If you are using the new version 3 of the new router. Then this will probably answer that question. How to get current route

In the V3 (RC.3) router you can inject ActivatedRoute and access more details using its snapshot property.

Community
  • 1
  • 1
wiredprogrammer
  • 545
  • 4
  • 13
  • The issue in question has to do with the fact that he hasn't properly installed and registered the angular 2 router module. If it was working before with ngrx, then this shouldn't be an issue. – Jaime Still Jul 29 '16 at 12:31
  • :-) and that is why I shouldn't try to answer stackoverflow questions before I've had my morning coffee. – wiredprogrammer Jul 29 '16 at 12:34
  • All good, glad you're trying to be helpful. Also, if you have Update 3 for Visual Studio 2015 and either TypeScript 1.8.4 or 2.0.0 beta extensions installed, then the above bug is no longer an issue. Note that if you have 1.8.4, you need to install the following nuget packages for TS to compile: Microsoft.TypeScript.Compiler and Microsoft.TypeScript.MSBuild – Jaime Still Jul 29 '16 at 12:37