angular2-routing

Argument of type '{header:Header;}' is not assignable to parameter of type 'RequestOptionsArgs'

半腔热情 提交于 2019-12-03 15:52:22
Im Getting following error while trying to pass header in HTTP.POST/GET request Argument of type '{header:Header;}' is not assignable to parameter of type 'RequestOptionsArgs'. Property 'null' is missing in the type '{header:Header;}' I have try many solutions but no lock on it. here my code : import { Injectable } from '@angular/core'; import { Response, RequestOptions, Headers, Http, URLSearchParams} from '@angular/http'; import { Observable, Subject } from 'rxjs/Rx'; import {Company} from './companyMaster'; import 'rxjs/add/operator/map'; import "rxjs/Rx"; import 'rxjs/add/operator

How do I Mock RouterStateSnapshot for a Router Guard Jasmine test

倖福魔咒の 提交于 2019-12-03 15:30:19
问题 I have a simple router guard and I am trying to test the canActivate( route: ActivatedRouteSnapshot, state: RouterStateSnapshot ) . I can create the ActivatedRouteSnapshot like this new ActivatedRouteSnapshot() but I cannot figure out how to create a mocked RouterStateSnapshot . Per the code I tried... let createEmptyStateSnapshot = function( urlTree: UrlTree, rootComponent: Type<any>){ const emptyParams = {}; const emptyData = {}; const emptyQueryParams = {}; const fragment = ''; const

Angular2, how to clear URL query params on router navigate

穿精又带淫゛_ 提交于 2019-12-03 15:24:48
问题 I am struggling with clearing out URL params during nav in Angular 2.4.2. I have tried attaching every option to clear the params in the below navigation line, or any mix therein with navigate, or navigateByUrl, but cannot figure out how to accomplish. this.router.navigateByUrl(this.router.url, { queryParams: {}, preserveQueryParams: false }); As an example I am at route /section1/page1?key1=abc&key2=def and want to stay at the same route but remove all the url parameters, so the end result

Component undefined has no route config aka how to configure Angular 2 router for unit test?

可紊 提交于 2019-12-03 15:14:25
I'm working on setting up a specification for routing with Angular2. This is the app component: import {Component, View} from 'angular2/core'; import {RouteConfig, ROUTER_DIRECTIVES} from 'angular2/router'; import {Search} from './search/search'; import {SearchResults} from './search-results/search-results'; @Component({ selector: 'my-app' }) @View({ template: `<div> <router-outlet></router-outlet> </div>`, directives: [ROUTER_DIRECTIVES] }) @RouteConfig([ {path: '/search', name: 'Search', component: Search, useAsDefault: true}, {path: '/search-results', name: 'SearchResults', component:

Angular2 - router-outlet with login structure

白昼怎懂夜的黑 提交于 2019-12-03 15:04:00
问题 I'm building angular2 app and currently I have an home component with navbar, toolbar and router-outlet for the main content. I want to add one extra page for the login mechanism, so if the user is not authenticated the login page will be displayed in the entire screen and after login to user will be navigated to the component with the structure above. How can I manage this structure? Do I need two router outlets? the first one for the navigation between login and home pages and one for the

How can I change a specific, internal route parameter in Angular2

北城以北 提交于 2019-12-03 14:09:02
问题 I am building a calendar that can display different kinds of data. The following example explains my URL structure I think: todo/2017/01/01 a day view of todos birthdays/2017/01/01 a day view of birthdays todo/2017/01 a month view of todos birthdays/2017/01 a month view of birthdays todo/2017 a year view of todos birthdays/2017 a year view of birthdays Up until now I have be able to pass in a Date object and reroute via this.router.navigate([#HARDCODED# 'todo' #OR# 'birthday', year, ?month,

How to hide link by guard angular2

ぃ、小莉子 提交于 2019-12-03 13:50:18
How to hide admin link in view html. I have to guard :Admin and Manager Router config : { path: 'manager', component: ManagerComponent, canActivate: [ManagerGuard] }, { path: 'user', component: UserAdminComponent, canActivate: [AdminGuard] } In view : <li> <a routerLink="/user" routerLinkActive="active-link">User</a> </li> I want to hide link on /user for ManagerGuard when but show for AdminGuard. Also if already answered in a way which might be helpful, I used here another approach. As you already have your canActivate method in the Guard, you could also inject your navigation component with

Angular2-router: How to only change a parameter of a route?

廉价感情. 提交于 2019-12-03 13:34:52
问题 I want to have the following routes in my application: export const routes: Routes = [ { path: ':universityId', component: UniversityComponent, children: [ { path: 'info', component: UniversityInfoComponent }, { path: 'courses/:status', component: CoursesByStatusComponent } ] } ] Being on /1/info or /1/courses/open url, how do I change :universityId only from UniversityComponent ? Simple router.navigate(['../', 2], {relativeTo: currentRoute }) won't do because it redirects to /2 , losing all

404 Error on refresh for angular(v4+) deployed on tomcat server

北战南征 提交于 2019-12-03 13:02:35
I have deployed an angular application with lazy loading. The application works perfectly when hosted on Github.io domain but I am getting an error when I deployed the app on tomcat server using mobaxterm. When the page reloads or refreshes the app loses the routing state and throws a 404 error. HTTP Status 404 - /enquiry type Status report message /enquiry description The requested resource is not available. Apache Tomcat/7.0.72 Console-Log:: GET http://appv2.proctur.com/enquiry/addEnquiry 404 (Not Found) Navigated to http://appv2.proctur.com/enquiry/addEnquiry If I do not refresh the page

Angular 2: Prevent router from adding to history

别说谁变了你拦得住时间么 提交于 2019-12-03 12:32:38
问题 We have a client that is iFraming in our app to their website. They don't want the router navigation within our app to affect the back button navigation for their own site. We've tried a couple methods including using post messages to try and have the iFrame communicate with the parent window whenever a history.back() is triggered. My question is if there is any easy way to not affect the browser's history when using Angular 2's router. As far as I know, I couldn't find anything within