#trying to change routerlink for a different component

1 messages Β· Page 1 of 1 (latest)

idle knoll
#

<li class="nav-item">
@if (userIsAdmin) {
<a class="nav-link" [routerLinkActive]="['active']" [routerLinkActiveOptions]="{exact: true}"
routerLink="/admin/admin-orders">Admin Orders</a>
}</li>

      <li class="nav-item">
        @if (userIsAdmin) {
          <a class="nav-link" [routerLinkActive]="['active']" [routerLinkActiveOptions]="{exact: true}"
          routerLink="/admin/admin-data">Data Website</a>
        }</li>

got 2 html links but the lead to the same routerlink and no clue how to fix it

#

let me know if i need to give more info πŸ™‚

elfin rover
#

you might want to provide your code formatted using Discord code blocks
helps with the readability a lot

<li class="nav-item">
@if (userIsAdmin) {
    <a
        class="nav-link"
        [routerLinkActive]="['active']"
        [routerLinkActiveOptions]="{exact: true}"
        routerLink="/admin/admin-orders">Admin Orders</a>
}
</li>

<li class="nav-item">
@if (userIsAdmin) {
    <a
        class="nav-link"
        [routerLinkActive]="['active']"
        [routerLinkActiveOptions]="{exact: true}"
        routerLink="/admin/admin-data">Data Website</a>
}
</li>
#

but to answer your question, make sure the routing module is loaded
especially if you are in standalone mode for your component, you might need to add some imports

idle knoll
#
import { DataWebshopComponent } from './data-webshop/data-webshop.component';

export const routes: Routes = [
  { path: '', component: HomeComponent },
  { path: 'products', component: ProductsComponent },
  { path: 'categories', component: CategoriesComponent,/* canActivate: [authGuard] */ },
  { path: 'cart', component: CartComponent },
  { path: 'auth/login', component: LoginComponent},
  { path: 'auth/register', component: RegisterComponent },
  { path: 'orders', component: OrdersComponent },  
  { path: 'admin', component: AdminComponent },
  { path: 'admin/admin-orders', component: AdminOrdersComponent },
  {path: 'admin/admin-data', component: DataWebshopComponent}

  //  { path: 'auth', children: [
  //      { path: 'login', component: LoginComponent },
  //       { path: 'register', component: RegisterComponent },
  //       { path: 'logout', }
  //    ]
  //  }
#

used them on the admin order so it is fine

#

@elfin rover do you got any idea?

elfin rover
#

what component does the links redirect to? AdminComponent?

idle knoll
elfin rover
#

doesn't it have something with the order the routes are declared in?

#

shouldn't you use nested routes for your admin pages?

idle knoll
elfin rover
#

what if you set the order as

  { path: 'admin/admin-data', component: DataWebshopComponent },
  { path: 'admin/admin-orders', component: AdminOrdersComponent },
  { path: 'admin', component: AdminComponent },
```?
#

Route order

The order of routes is important because the Router uses a first-match wins strategy when matching routes, so more specific routes should be placed above less specific routes. List routes with a static path first, followed by an empty path route, which matches the default route. The wildcard route comes last because it matches every URL and the Router selects it only if no other routes match first.

idle knoll
elfin rover
#

wdym?

#

you might want to read the doc sample I just sent

#

especially the

more specific routes should be placed above less specific routes. List routes with a static path first, followed by an empty path route, which matches the default route
part

idle knoll
# elfin rover wdym?

want admin orders to see the order data of the user and data to see updated data from database frompowerbi

idle knoll
#

will fix the design later but what should i do?

elfin rover
#

hollander? πŸ‘€

idle knoll
elfin rover
#

kaaskop HA

idle knoll
elfin rover
#

more specific routes should be placed above less specific routes. List routes with a static path first, followed by an empty path route, which matches the default route

idle knoll
#

don t understand it so won t get muc further

elfin rover
#

routes in correct order bepalen
van meest precies to minst precies/meest generiek

#

admin/admin-data is meer precies dan admin dus moet eerst

#

en admin moet laast

idle knoll
#

maar dat zijn alleen detials want veranderd niet veel toch?

elfin rover
#

jawel

idle knoll
#

voor voor 2 uur in de nacht powerbi fixen lol

elfin rover
elfin rover
#

nested routes kan ook

idle knoll
#

dus childcomponents onder de hoofdclass
clean code intreseerd mij voor nu niet zo heel veel wil het werkend hebben dus net gammel genoeg om te werken XD

elfin rover
idle knoll
elfin rover
#

nu wel, met admin laatst

idle knoll
#

en dan?

elfin rover
#

dan wat?
het zou moeten lukken

idle knoll
#

houdt nog steeds bij orders en data de orders path aan

elfin rover
#

nav component toch goed opgeslagen?

#

en geen compileerfout

idle knoll
#
  selector: 'app-navigation',
  standalone: true,
  imports: [RouterModule, FormsModule],
  templateUrl: './navigation.component.html',
  styleUrl: './navigation.component.scss'
})
export class NavigationComponent implements OnInit {
  public title: string = 'INFIRFS - Webshop';
  // searchtext: any;


  public amountOfProducts: number = 0;

  constructor(private cartService: CartService, private authService: AuthService, private router: Router) { }

  ngOnInit() {
    this.cartService.$productInCart.subscribe((products: Product[]) => {
      this.amountOfProducts = products.length;
      this.checkLoginState();
    })
  }

   
  public showHotCupIcon: boolean = false;
  public userIsLoggedIn: boolean = false;
  public userIsAdmin: boolean = false;
 
 
  public onLogout(): void{
    this.authService.logOut();
    this.userIsAdmin = false; 
    this.router.navigate(['/']);
  }
 
  public checkLoginState(): void{
 
    this.authService
      .$userIsLoggedIn
      .subscribe((loginState: boolean) => {
        this.userIsLoggedIn = loginState;
        if (localStorage.getItem('email') === "[email protected]" || localStorage.getItem('email') === "[email protected]"){
          this.userIsAdmin = true;
        }
      });
  }


  public fontChange(size: string){
    const root = document.querySelector(":root") as HTMLElement;

    if (root){
      root.style.fontSize = size;
    }
  }
#

doe wel ff ng serve

#

als je ooit in die admin rol bent gekomen en daarna weer user bent heb je een probleem XD get local storage in incognito is het niet

#

nu laat hij trouwens niks meer zien als je de paths verplaatst

#

πŸ™ƒ

#

@elfin rover

#

nu pakt hij het wel πŸ™‚

elfin rover
#

geen idee

#

misschien de hele code effe opsturen

idle knoll
#

werk je echt met angular als baan🀨 thonk

elfin rover
#

yep

#

gewoon niet iets wat we dagelijks doen

idle knoll
elfin rover
#

fullstack dev (voor overheidsdiensten)
meestal Spring Boot voor de backend en Angular voor de frontend

#

meeste van onze apps hebben slechts een paar pagina's

#

vooral tabellen

#

geen admin dashboard ofzo