I am trying to develop an application with Spring Boot for the back and Angular 2 for the interface using maven.
The Angular 2 interface is located in the src/main/resources/static directory of the project.
When I enter the URL http://localhost:8080/ in my browser, everything is fine: I can access the Angular 2 interface and the interface can interact perfectly with the rest of the api. My Angular 2 trace works fine: when I click the link on the front side, I go to the right page and the browser url line shows the right things (i.e. http://localhost:8080/documents )
But the problem is that I am trying to directly write the same URL in the browser. Spring takes the front end and says there is no mapping for /documents .
Is there a way to tell Spring to load only for "listening" /api/* URLs and for "redirecting" everyone else to the interface?
Here is my Spring Controller class:
@RestController @RequestMapping("/api") public class MyRestController { @Autowired private DocumentsRepository documentRepository; @CrossOrigin(origins = "*") @RequestMapping(value = "/documents/list", method = RequestMethod.GET, produces = "application/json") public Iterable<RfDoc> findAllDocuments() { return documentRepository.findAll(); } }
Here is the main class of the application:
@SpringBootApplication public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } }
Here is my app.route.ts:
import { provideRouter, RouterConfig } from '@angular/router'; import { DocumentComponent } from './doc.component'; const routes: RouterConfig = [ { path: '', redirectTo: 'documents', pathMatch: 'full' }, { path: "documents", component: DocumentComponent } ]; export const appRouterProviders = [ provideRouter(routes) ];
source share