發表文章

目前顯示的是 11月 4, 2018的文章

Angular 6: Guard on all routes is not working

圖片
up vote 0 down vote favorite I'm trying to make the frontend secured by only letting certain Id's getting access. I want that If someone try to enter any route except for /login/:id, he'll get page-not-found if he didn't logged already, but it's not working. These are my routing table and guard: EDIT: I edited the routing table and added to 'login/:id' redirectTo, and now there aren't any errors, but the id is undefined so it's go to page-not-found component even though I entered login/1. when I tried to debug the code, I noticed that the route isn't of login/1 but '' even if I wrote in the url login/1. app-routing.module.ts // Routing array - set routes to each html page const appRoutes: Routes = [ { path: 'login/:id', redirectTo:'/courses', canActi

Unhandled Rejection (TypeError): Cannot read property of undefined

圖片
up vote 0 down vote favorite I can't find out why i can't get the data, while I can access it through console.log() ! export class InnerTicket extends React.Component{ constructor(props){ super(props); this.state = { ticket: '' } } componentDidMount() { this.getTicket().then(result => this.setState({ ticket: result })) } getTicket(){ const slug = this.props.match.params.id; return this.props.TicketsStore.loadTicket(slug); } render(){ console.log(this.state); everything works fine when I run this and i can see the data through the console: {ticket: {…}}ticket: {success: true, data: {…}, error: "", message: ""}data: {result: "success", ticketid: 22, tid: "168552", c: "WHgCsCBO", deptid: 5, …}er