I would like to start navigation from http://mysite.com/hello/world
, not from site root.
e.g.
$routeProvider
.when('/myurl', {
templateUrl: 'mytmpl.html',
controller: 'MyCtrl'
});
should react when my url is http://mysite.com/hello/world/myurl
How could I do that?
To make your applications ready for routing, you must include the AngularJS Route module: Then you must add the ngRoute as a dependency in the application module: Now your application has access to the route module, which provides the $routeProvider. Use the $routeProvider to configure different routes in your application:
It is a "batteries-included" framework that comes with many powerful libraries and modules baked in so that you can start building your app quickly. One of the features that Angular includes out-of-the-box is the Angular Router. In this guide, you will learn how to use the Angular Router— specifically the forRoot and forChild static methods.
Note: The Angular CLI does not let you use the --routing parameter until version 8.1. The forRoot static method is the method that configures the root routing module for your app. When you call RouterModule.forRoot (routes), you are asking Angular to instantiate an instance of the Router class globally.
When you call RouterModule.forRoot (routes), you are asking Angular to instantiate an instance of the Router class globally. Just like Angular creates a new base AppModule to import all of your feature modules, it also provides the AppRoutingModule to import all of your child routes.
Add base tag to the main HTML file that is being served when user navigates to http://example.com/hello/world
:
<base href="/hello/world/" />
More info can be found at Developer Guide / Using $location
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