I am using Angular 2.0.0-alpha.30 version. When redirect to a different route, then refresh the browser , its showing Cannot GET /route.
Can you help me with figuring why this error happened.
Use LoadChildren:For lazy loading. Using this property will optimize your application's performance by only loading the nested route subtree when a user navigates to a particular URL that matches the current route path. It helps in keeping the nested routes table separate.
Add the AppRoutingModule link. In Angular, the best practice is to load and configure the router in a separate, top-level module. The router is dedicated to routing and imported by the root AppModule . By convention, the module class name is AppRoutingModule and it belongs in the app-routing.
RouterLink is a built-in Angular Directive that lets you link to specific routes in your app. In the SPA(single-page application), you change what the user sees by showing or hiding portions of the display that correspond to particular components, rather than going out to the server to get a new page.
angular-cli (as of version 6 at least) always uses RouterModule. forChild() when generating a new module. Only when using --routing with ng new it uses RouterModule. ForRoot() as import in the routing-module.
The error you are seeing is because you are requesting http://localhost/route which doesn't exist. According to Simon.
When using html5 routing you need to map all routes in your app(currently 404) to index.html in your server side. Here are some options for you:
using live-server: https://www.npmjs.com/package/live-server
$live-server --entry-file=index.html`
using nginx: http://nginx.org/en/docs/beginners_guide.html
error_page 404 /index.html
Tomcat - configuration of web.xml. From Kunin's comment
<error-page>
<error-code>404</error-code>
<location>/index.html</location>
</error-page>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With