Giter Club home page Giter Club logo

Comments (10)

djds4rce avatar djds4rce commented on June 29, 2024

If iam not wrong this issue is because the app-view-segment chain isnt flushed before a route change instead it is incrementally substituted which causes this issue. It would be great it this was fixed, cause this causes a lot of nasty issues.

Edit: Just found a fix for it #7
Edit2: Sorry it is a unrelated issue.

from angular-route-segment.

marutib avatar marutib commented on June 29, 2024

I am also getting the same problem .. here is my plunkr http://plnkr.co/edit/VPFOi7?p=preview

Please check console.logs to see the error

Here is the hierarchy

/listing ( cntrller :- listing_index )
-> /listing/myListing ( cntrller :- my_listing )
/promotion ( cntrller :- promotion_index )
-> /promotion/list ( cntrller :- promotion_list )

Initially the default url is /listing/myListing so it calls the following controllers ( listing_index,my_listing )

Now on clicking a link which takes to /promotion/list the following controllers are called ( promotion_index, my_listing, promotion_list )

why is my_listing getting called again ??

Please check console for the errors

from angular-route-segment.

jamie-pate avatar jamie-pate commented on June 29, 2024

+1, this should not be happening!
A workaround I found was to use a guard in the controller.

Compare $route.current.$$route.segment === $routeSegment.name

if ($route.current.$$route.segment === $routeSegment.name) {
//do stuff that should only happen when the
// *correct* segment is being initialized
}

PS: angular-route-segment v1.2.0

from angular-route-segment.

naczu avatar naczu commented on June 29, 2024

@jamie-pate that controller should never fired.

from angular-route-segment.

jamie-pate avatar jamie-pate commented on June 29, 2024

@naczu It is fired though :)

PS: this workaround only works for controllers that are used in the right-most segment.

EG: route: x.y.z <- code only works in controller for z

from angular-route-segment.

jamie-pate avatar jamie-pate commented on June 29, 2024

Ok, so. I figured out the 'correct' workaround for my problem. The issue for me was caused by calling $location.path(newPath) inside the constructor for a controller in one of the routes.

I was also mixing $routeProvider and $routeSegmentProvider and angular-route-segment wasn't updating the $routeSegment properly when the route wasn't a segment!

The solution was to not mix $routeProvider and $routeSegmentProvider

from angular-route-segment.

abhikmitra avatar abhikmitra commented on June 29, 2024

+1 .Suffering form the same issue . @jamie-pate do you have a plunkr to illustrate your solution ?

from angular-route-segment.

jamie-pate avatar jamie-pate commented on June 29, 2024

If you have a plunkr to illustrate your problem, I might be able to fix it?

from angular-route-segment.

marutib avatar marutib commented on June 29, 2024

Hi @jamie-pate , will this do :- http://plnkr.co/edit/VPFOi7?p=preview

from angular-route-segment.

jamie-pate avatar jamie-pate commented on June 29, 2024

That plunkr seems to work fine (no error messages)

It seems like $routeProvider is needed for redirects? I needed dynamic redirects so I ended up having to create a controller that did the job

   $routeSegmentProvider
     .when('/original/path', 'desired.segment_redirect')
     .when('/desired/segment', 'desired.segment')
     .segment('desired.segment_redirect', {
        template: '',
        controller: 'Redirect'
     })
     .segment('desired', {...})
     .within()
        .segment('segment', { ...})

    module.controller('Redirect',Redirect);
    function Redirect($location, persistentStorage) {
        var type = persistentStorage.get(type_key);
        $location.replace().path($location.path() + '/' + type);
    }

from angular-route-segment.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.