简体   繁体   中英

Read url requested in Angular app

When a page loads, I want to determine what url was used to load that page and intercept it in the controller so I can extract the parameters from it.

For example if http://mypage.com/#/myPage/otherStuff

How can I intercept this URL before the page loads?

Thank you.

(Use case) 1. user requests my page 2. I intercept, take out the parameters from the url 3. I format the page to match their parameters.

It sounds like you're looking for these events (read the docs here).

$scope.$on("$locationChangeStart", function (event, nextLocation, currentLocation) {

});

From reading the comments, I see that your question is an X/Y issue. My answer deals with your question of intercepting the url in the controller, but it looks like your overall goal is better accomplished by other means.

我建议使用ngRouteui-router定义路由,并将uri的可变部分设置为路由参数,然后在控制器功能中可用。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM