0

I am currently using the new AnalogJS and I added a routerLink to a component that takes in the role (String) which can be either Designer/Creator. The route takes in a role param and the component accesses the param to get the string value. But the routerLink always doesn't work. UNLESS I reload the page. Super weird.

<a [routerLink]="['/signup/creator']" class="flex-1 my-6">
  <div class="mx-auto">
    ...
  </div>
</a>

I added RouterLink to import as well

@Component({
  selector: "app-signuprole",
  standalone: true,
  imports: [HeaderComponent, FooterComponent, RouterModule, RouterLink],
  templateUrl: "./(layouts)/signuprole.page.html",
})

I tried using Router by adding it to the constructor as shown below.

constructor(private router: Router) { }

navigateToSignup(role: string) {
  this.router.navigate(["/signup", role]);
}

and I added the click functionality instead of the routerLink='...', nevertheless it did not work as well.

UPDATE: window.location.href = '...'. Always works! but isnt this horrible for AnalogJS

4
  • Can you share your app.routing.ts? Commented Apr 15, 2024 at 8:03
  • { path: "signup/:role", component: SignUpComponent, }, This is pretty much the path. export const appConfig: ApplicationConfig = { providers: [ provideFileRouter(), provideHttpClient(withFetch()), provideClientHydration(), provideRouter(routes), ], }; Commented Apr 15, 2024 at 8:20
  • Do you get any errors in the browser console? Can you recreate it in StackBlitz? I see & tested the code is fine. Demo Commented Apr 16, 2024 at 2:30
  • I get a conflict error after running the project for a while. It seems to build up more conflicts as I continue to explore the website. Error: angular.io/errors/NG0912 Commented Apr 16, 2024 at 2:35

2 Answers 2

0

You just need to modify the [routerLink] value inside the template a little bit to use a comma when passing the dynamic segment of the route (:role):

signuprole.page.html:

<a [routerLink]="['/signup', role]" class="flex-1 my-6">
  <div class="mx-auto">
    ...
  </div>
</a>

signuprole.component.ts:

import { Component } from '@angular/core';

    @Component({
      selector: "app-signuprole",
      standalone: true,
      imports: [HeaderComponent, FooterComponent, RouterModule, RouterLink],
      templateUrl: "./(layouts)/signuprole.page.html",
    })
    export class SignUpRoleComponent {
      role: string = 'creator'; // set initial role
    }
Sign up to request clarification or add additional context in comments.

1 Comment

Nope this is what I originally did on my AnalogJS Project
0

window.location.href = "..." This always works but might be horrible for projects

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.