P
P
Pavel Talaiko2018-06-21 15:10:13
Angular
Pavel Talaiko, 2018-06-21 15:10:13

Why doesn't spring boot return Angular 5 pages by url?

Hello! Dear toasters, what's the problem? Spring Boot is written by API, Angular 5 front. It's time for deployment. I built the project in Spring Boot resources/static/* everything works, cheers. But when you reload the page, Sping Security is triggered and says that the url is not very good and the client logic sometimes does not work, as if the scripts were not loaded. Details on screenshots.
Put ignore for files.
5b2b93dc4599b879037596.png
Launched - works. But when I switch not to "/" but let's say "/signin" and reload F5. then I get 401. As if I'm not stepping on Angular, but on an API to which I do not have access.
5b2b9459a5752908694732.png
You can see what the problem is with GIF here VIEW GIF .

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
Pavel Talaiko, 2018-06-24
@jsdevel

Solution.

package by.psu.controllers;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class ViewController {

    @RequestMapping(value = "/**/{[path:[^\\.]*}")
    public String redirect() {
        return "forward:/";
    }
}

R
RidgeA, 2018-06-21
@RidgeA

I don’t know how in spring, but the server needs to redirect all requests to the same entry point to the Angular application.
And there is

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question