Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

$locationChangeStart: difficult to preventDefault then allow via $location.path(newurl) #8617

Open
@WhatFreshHellIsThis

Description

@WhatFreshHellIsThis

This is not really a bug, it's a nuisance:

It's a common use case in an application to prompt the user when a route change is detected with the current page editing a dirty record.

To do this we need to add a listener for $locationChangeStart event. This listener gets called with the event and the new url that would be navigated to.

In this event we preventDefault and then prompt the user if they really want to navigate away from a dirty record. If they say "yes" then we have a problem because the new url parameter passed to our handler is actually the entire path and if we feed it to $location.path(newUrl) it fails because it's the entire url, not just the part that $location.path expects.

This means we need to resort to some possibly sketchy parsing along these lines:
http://stackoverflow.com/questions/20303073/angularjs-location-path-with-full-url

It would be nice to be able to pass the newUrl parameter from the $locationChangeStart event directly to the $location.path() method.

Or, alternatively, if $location.path was smart enough to recognize and handle this situation.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions