【发布时间】:2018-05-25 07:09:35
【问题描述】:
下面是sn-p的代码:
进口{ 路由器 } 来自“@angular/路由器”; 进口 { HttpClient } 来自“@angular/common/http”; 进口 { 环境 } 来自“../../environments/environment”; 进口 { 地点, 位置策略, 路径定位策略 } 来自“@angular/common”;
@Injectable()
export class CommonServicesService {
PathLocation: Location;
referralCode: any = localStorage.getItem('referenceCode');
constructor(
location: Location,
) {
this.PathLocation = location;
}
redirectAfterSuccessfulLogin() {
if (localStorage.getItem("redirectUrl")) {
let url = localStorage.getItem("redirectUrl");
localStorage.removeItem("redirectUrl");
this.PathLocation.prepareExternalUrl("'/'+this.referralCode"); //is this the correct way?
console.log(this.PathLocation);
this.router.navigate([url]);
} else {
this.PathLocation.prepareExternalUrl("'/'+this.referralCode");
console.log(this.PathLocation);
this.router.navigate(["/"]);
}
}
}
【问题讨论】:
-
您是否在登录后尝试从一个网址导航到另一个网址?比如从 'localhost:3000/home' 到 'localhost:3000/home/code' 或者你想改变应用程序的基本 url?
-
我想把base_href从localhost:3000改成localhost:3000/23232
标签: angular5 angularjs-ng-href