Wildcard (**) path not catching all other paths in Spring Boot/Angular app

Discussão em 'Angular' iniciado por user30200080, Abril 7, 2025.

  1. user30200080

    user30200080 Guest

    I have a Spring Boot (3.4.4) on java (24 2025-03-18) and Angular (19.2.5) application:

    I have a routing array

    export const routes: Routes = [
    {path: '', component: HomePageComponent},
    {path: 'aboutMe', component: AboutMeComponent},
    ...
    //{path: '**', component: PageNotFoundComponent},
    {path: '**', component: PageNotFoundComponent, pathMatch: 'full'}
    ];


    where routes work when I try localhost/aboutMe, but when I try something like localhost/about:

    Whitelabel Error Page
    This application has no explicit mapping for /error, so you are seeing this as a fallback.

    Mon Apr 07 14:21:23 EDT 2025
    There was an unexpected error (type=Not Found, status=404).


    and in the inspect window says:

    http://localhost:8080/about 404 (Not Found)


    and as you can see I have tried both pathMatch and without.

    If I use my webpage to go to /aboutMe it will work then likewise I refresh and get the error.

    I do have connection between the Angular front end and Java backend because I know

    this.httpClient.get<any[]>('/resource');


    and then a subscribe

    this.aboutMeService.getAboutMeService().subscribe(
    (data) => { info = data; });


    results in data being returned from the Java backend

    Everything else in my app works fine. If I try just an Angular project with no Java backend the wildcard path works. I understand the cause is from the backend Java server not having the end points, but I want to make it so when a URL is typed in it won't hit the backend unless I have code to make it do so.

    More simply I want my Angular code to make the requests to the Java backend, not the URL.

    How can I get this functionality?

    Continue reading...

Compartilhe esta Página