[AngularJS] Store the entry url and redirect to entry url after Logged in

Posted Answer1215

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[AngularJS] Store the entry url and redirect to entry url after Logged in相关的知识,希望对你有一定的参考价值。

For example when a outside application need to visit your app address:

https://www.example.com/#/lobby/abc

But before enter ‘/lobby/abc‘, user need to login, so the application will redirect user to 

https://www.example.com/#/login

Now what you want is after user logged in, you can redirect them to 

https://www.example.com/#/lobby/abc

Instead of other pages like:

https://www.example.com/#/lobby

 

So to solve the problem, we need to do two things

1. Store the entry url

2. After logged in, redirect user to entry url

 

1. Store the entry ur:

angular.module(‘app‘)
     // When can get pull url by using $location.absUrl()
    // Because run block only run once for the module and app module is our main application module, so this should only store our entry url
    // To reuse the entryUrl later, we store it in LoginService
    .run(($location, LoginService) => LoginService.entryUrl = $location.absUrl())

 

2. After logged in, then we can redirect user to the entry url by doing:

$location.url(LoginService.entryUrl)

 

以上是关于[AngularJS] Store the entry url and redirect to entry url after Logged in的主要内容,如果未能解决你的问题,请参考以下文章

[Redux] Passing the Store Down Implicitly via Context

[Immutable + AngularJS] Use Immutable .List() for Angular array

7.4 Models -- Pushing Records into the Store

python 来自https://stackoverflow.com/questions/23602412/only-download-a-part-of-the-document-using-pyt

LeetCode(数据库)- The Category of Each Member in the Store

iOS开发上传App Store时候一直卡在 Authenticating with the iTunes Store 的解决办法 2017-05-04 10:33