在本文中,我们将带你了解msal和angular4重定向Url在这篇文章中,我们将为您详细介绍msal和angular4重定向Url的方方面面,并解答angular路由重定向常见的疑惑,同时我们还将给
在本文中,我们将带你了解msal和angular 4重定向Url在这篇文章中,我们将为您详细介绍msal和angular 4重定向Url的方方面面,并解答angular 路由重定向常见的疑惑,同时我们还将给您一些技巧,以帮助您实现更有效的Angular ui路由器单元测试(指向URL的状态)、Angular 下载属性重定向到 url 而不是下载、angular+ 路由学习 (十)重定向迁移URL、angular+ 路由学习 (十)重定向迁移URL (复制官文)。
本文目录一览:- msal和angular 4重定向Url(angular 路由重定向)
- Angular ui路由器单元测试(指向URL的状态)
- Angular 下载属性重定向到 url 而不是下载
- angular+ 路由学习 (十)重定向迁移URL
- angular+ 路由学习 (十)重定向迁移URL (复制官文)
msal和angular 4重定向Url(angular 路由重定向)
我的app.routing模块如下所示:
const routes: Routes = [ { path: 'authentication',component: LoginComponent },{ path: '',redirectTo: '/lists',pathMatch: 'full',canActivate: [AuthenticationGuard] },{ path: 'lists',component: ApplicationContainer,canActivate: [AuthenticationGuard]} ]; @NgModule({ imports: [RouterModule.forRoot(routes)],exports: [RouterModule] }) export class AppRoutingModule { }
我的问题是当用户登录时我得到令牌并且当redirecturi到达’/ lists’时.我有一个gaurd.在gaurd的一侧,由于页面未重定向,因此尚未设置标记值.这就是为什么它一直都是假的,我被重定向回登录页面.
解决方法
npm install @azure/msal-angular --save
Angular ui路由器单元测试(指向URL的状态)
我在应用程序中测试路由器时遇到了一些麻烦,该应用程序是基于Angular
ui路由器构建的。我要测试的是状态转换是否适当地更改了URL(稍后将进行更复杂的测试,但这是我开始的地方。)
这是我的应用程序代码的相关部分:
angular.module(''scrapbooks'') .config( function($stateProvider){ $stateProvider.state(''splash'', { url: "/splash/", templateUrl: "/app/splash/splash.tpl.html", controller: "SplashCtrl" }) })
和测试代码:
it("should change to the splash state", function(){ inject(function($state, $rootScope){ $rootScope.$apply(function(){ $state.go("splash"); }); expect($state.current.name).to.equal("splash"); })})
关于Stackoverflow的类似问题(以及官方ui路由器测试代码)表明,将$ state.go调用包装在$
apply中应该足够了。但是我已经做到了,状态仍然没有更新。$ state.current.name保持为空。
答案1
小编典典同样也遇到了这个问题,最终找到了解决方法。
这是一个示例状态:
angular.module(''myApp'', [''ui.router'']).config([''$stateProvider'', function($stateProvider) { $stateProvider.state(''myState'', { url: ''/state/:id'', templateUrl: ''template.html'', controller: ''MyCtrl'', resolve: { data: [''myService'', function(service) { return service.findAll(); }] } });}]);
下面的单元测试将涵盖测试带参数的URL,以及执行注入自身依赖关系的解析:
describe(''myApp/myState'', function() { var $rootScope, $state, $injector, myServiceMock, state = ''myState''; beforeEach(function() { module(''myApp'', function($provide) { $provide.value(''myService'', myServiceMock = {}); }); inject(function(_$rootScope_, _$state_, _$injector_, $templateCache) { $rootScope = _$rootScope_; $state = _$state_; $injector = _$injector_; // We need add the template entry into the templateCache if we ever // specify a templateUrl $templateCache.put(''template.html'', ''''); }) }); it(''should respond to URL'', function() { expect($state.href(state, { id: 1 })).toEqual(''#/state/1''); }); it(''should resolve data'', function() { myServiceMock.findAll = jasmine.createSpy(''findAll'').and.returnValue(''findAll''); // earlier than jasmine 2.0, replace "and.returnValue" with "andReturn" $state.go(state); $rootScope.$digest(); expect($state.current.name).toBe(state); // Call invoke to inject dependencies and run function expect($injector.invoke($state.current.resolve.data)).toBe(''findAll''); });});
Angular 下载属性重定向到 url 而不是下载
如何解决Angular 下载属性重定向到 url 而不是下载?
我正在尝试使用我的 href 标签从链接下载,但它会将我带到 URL 而不是下载实际文件。这是我的 ts:
public getCiCdInputFromUser(value: any) {
this.userService.getCicdFile(value).subscribe((test => {
this.specificationUrl = test;
console.log(test);
}));
}
这是我的 html:
<a
mat-raised-button
color="accent"
[href]="specificationUrl"
download="specificationUrl"
>
Download CICD File
</a>
我的 service.ts:
getCicdFile = (language: string): Observable<Cicdlanguage> => {
const headers = new HttpHeaders().set(''Content-Type'',''text/plain; charset=utf-8'');
return this.http
.post<Cicdlanguage>(`${environment.apiUrl}/cicd`,{language},{ headers,responseType: ''text'' as ''json'' })
.pipe(
catchError(err => {
console.log(''error'',err);
return EMPTY;
})
);
}
和我的 CicdLanguage:
export class Cicdlanguage {
public language: string;
}
我将我的规范 Url 设置为假设要下载的链接,但它会在新选项卡中打开文件
我尝试下载的文件是 Yaml 文件
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)
angular+ 路由学习 (十)重定向迁移URL
-
把
/heroes
修改为/superheros
先取得 Hero
路由,并把它们迁移到新的 URL。
(路由器)会在开始导航之前先在配置中检查所有重定向语句,以便将来按需触发重定向。要支持这种修改,你就要在 heroes-routing.module
文件中把老的路由重定向到新的路由。
// hero-routing.module.ts import { NgModule } from ''@angular/core''; import { RouterModule, Routes } from ''@angular/router''; import { HeroListComponent } from ''./hero-list/hero-list.component''; import { HeroDetailComponent } from ''./hero-detail/hero-detail.component''; const heroesRoutes: Routes = [ { path: ''heroes'', redirectTo: ''/superheroes'' }, { path: ''hero/:id'', redirectTo: ''/superhero/:id'' }, { path: ''superheroes'', component: HeroListComponent, data: { animation: ''heroes'' } }, { path: ''superhero/:id'', component: HeroDetailComponent, data: { animation: ''hero'' } } ]; @NgModule({ imports: [ RouterModule.forChild(heroesRoutes) ], exports: [ RouterModule ] }) export class HeroesRoutingModule { }
-
app-routing.module.ts
中修改空路径路由,让它重定向到/superheroes
。import { NgModule } from ''@angular/core''; import { RouterModule, Routes, PreloadAllModules } from ''@angular/router''; import { ComposeMessageComponent } from ''./compose-message/compose-message.component''; import { PageNotFoundComponent } from ''./page-not-found/page-not-found.component''; import { AuthGuard } from ''./auth/auth.guard''; import { SelectivepreloadingStrategyService } from ''./selective-preloading-strategy.service''; const appRoutes: Routes = [ { path: ''compose'', component: ComposeMessageComponent, outlet: ''popup'' }, { path: ''admin'', loadChildren: () => import(''./admin/admin.module'').then(mod => mod.AdminModule), canLoad: [AuthGuard] }, { path: ''crisis-center'', loadChildren: () => import(''./crisis-center/crisis-center.module'').then(mod => mod.CrisisCenterModule), data: { preload: true } }, { path: '''', redirectTo: ''/superheroes'', pathMatch: ''full'' }, { path: ''**'', component: PageNotFoundComponent } ]; @NgModule({ imports: [ RouterModule.forRoot( appRoutes, { enableTracing: false, preloadingStrategy: SelectivepreloadingStrategyService, } ) ], exports: [ RouterModule ] }) export class AppRoutingModule { }
- 由于
指令没有关联到路由配置,所以你需要修改相关的路由链接,以便在新的路由激活时,它们也能保持激活状态。你要修改RouterLink app.component.ts
模板中的/heroes
路由链接。<h1>Angular Router</h1> <nav> <a routerLink="/crisis-center" routerLinkActive="active">Crisis Center</a> <a routerLink="/superheroes" routerLinkActive="active">Heroes</a> <a routerLink="/admin" routerLinkActive="active">Admin</a> <a routerLink="/login" routerLinkActive="active">Login</a> <a [routerLink]="[{ outlets: { popup: [''compose''] } }]">Contact</a> </nav> <div [@routeAnimation]="getAnimationData(routerOutlet)"> <router-outlet #routerOutlet="outlet"></router-outlet> </div> <router-outlet name="popup"></router-outlet>
- 修改
hero-detail.component.ts
中的goToHeroes()
方法,使用可选的路由参数导航回/superheroes
。gotoHeroes(hero: Hero) { let heroId = hero ? hero.id : null; this.router.navigate([''/superheroes'', { id: heroId, foo: ''foo'' }]); }
总结
以上是小编为你收集整理的angular+ 路由学习 (十)重定向迁移URL全部内容。
如果觉得小编网站内容还不错,欢迎将小编网站推荐给好友。
原文地址:https://www.cnblogs.com/gushiyoyo/p/11276776.html
angular+ 路由学习 (十)重定向迁移URL (复制官文)
-
把
/heroes
修改为/superheros
先取得 Hero
路由,并把它们迁移到新的 URL。Router
(路由器)会在开始导航之前先在配置中检查所有重定向语句,以便将来按需触发重定向。要支持这种修改,你就要在 heroes-routing.module
文件中把老的路由重定向到新的路由。
// hero-routing.module.ts
import { NgModule } from ''@angular/core'';
import { RouterModule, Routes } from ''@angular/router'';
import { HeroListComponent } from ''./hero-list/hero-list.component'';
import { HeroDetailComponent } from ''./hero-detail/hero-detail.component'';
const heroesRoutes: Routes = [
{ path: ''heroes'', redirectTo: ''/superheroes'' },
{ path: ''hero/:id'', redirectTo: ''/superhero/:id'' },
{ path: ''superheroes'', component: HeroListComponent, data: { animation: ''heroes'' } },
{ path: ''superhero/:id'', component: HeroDetailComponent, data: { animation: ''hero'' } }
];
@NgModule({
imports: [
RouterModule.forChild(heroesRoutes)
],
exports: [
RouterModule
]
})
export class HeroesRoutingModule { }
-
app-routing.module.ts
中修改空路径路由,让它重定向到/superheroes
。import { NgModule } from ''@angular/core''; import { RouterModule, Routes, PreloadAllModules } from ''@angular/router''; import { ComposeMessageComponent } from ''./compose-message/compose-message.component''; import { PageNotFoundComponent } from ''./page-not-found/page-not-found.component''; import { AuthGuard } from ''./auth/auth.guard''; import { SelectivePreloadingStrategyService } from ''./selective-preloading-strategy.service''; const appRoutes: Routes = [ { path: ''compose'', component: ComposeMessageComponent, outlet: ''popup'' }, { path: ''admin'', loadChildren: () => import(''./admin/admin.module'').then(mod => mod.AdminModule), canLoad: [AuthGuard] }, { path: ''crisis-center'', loadChildren: () => import(''./crisis-center/crisis-center.module'').then(mod => mod.CrisisCenterModule), data: { preload: true } }, { path: '''', redirectTo: ''/superheroes'', pathMatch: ''full'' }, { path: ''**'', component: PageNotFoundComponent } ]; @NgModule({ imports: [ RouterModule.forRoot( appRoutes, { enableTracing: false, preloadingStrategy: SelectivePreloadingStrategyService, } ) ], exports: [ RouterModule ] }) export class AppRoutingModule { }
- 由于
RouterLink
指令没有关联到路由配置,所以你需要修改相关的路由链接,以便在新的路由激活时,它们也能保持激活状态。你要修改app.component.ts
模板中的/heroes
路由链接。<h1>Angular Router</h1> <nav> <a routerLink="/crisis-center" routerLinkActive="active">Crisis Center</a> <a routerLink="/superheroes" routerLinkActive="active">Heroes</a> <a routerLink="/admin" routerLinkActive="active">Admin</a> <a routerLink="/login" routerLinkActive="active">Login</a> <a [routerLink]="[{ outlets: { popup: [''compose''] } }]">Contact</a> </nav> <div [@routeAnimation]="getAnimationData(routerOutlet)"> <router-outlet #routerOutlet="outlet"></router-outlet> </div> <router-outlet name="popup"></router-outlet>
- 修改
hero-detail.component.ts
中的goToHeroes()
方法,使用可选的路由参数导航回/superheroes
。gotoHeroes(hero: Hero) { let heroId = hero ? hero.id : null; this.router.navigate([''/superheroes'', { id: heroId, foo: ''foo'' }]); }
关于msal和angular 4重定向Url和angular 路由重定向的问题我们已经讲解完毕,感谢您的阅读,如果还想了解更多关于Angular ui路由器单元测试(指向URL的状态)、Angular 下载属性重定向到 url 而不是下载、angular+ 路由学习 (十)重定向迁移URL、angular+ 路由学习 (十)重定向迁移URL (复制官文)等相关内容,可以在本站寻找。
本文标签: