This might be a dumb question but I am new to Angular and haven't gotten an answer for this.
I was following a tutorial and have my routes set up like this for my Angular 5 project:
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { PageComponent } from './page/page.component';
const appRoutes: Routes = [
{path: '', redirectTo: '/home', pathMatch: 'full'},
{path: 'home', component: PageComponent, data: {
page: 'home'
}},
{path: 'about', component: PageComponent, data: {
page: 'about'
}},
{path: 'contact', component: PageComponent, data: {
page: 'contact'
}},
{path: 'facebook', component: PageComponent, data: {
page: 'facebook'
}},
{path: '**', redirectTo: '/home', pathMatch: 'full'}
];
@NgModule({
imports: [RouterModule.forRoot(appRoutes)],
exports: [RouterModule]
})
export class AppRoutingModule {
}
Let's say I want to route the "facebook" path to my facebook page. I am not sure how to route to pages outside of the Angular Application.
Any help would be appreciated!
Auxiliary Routes are independent, secondary routes that can be added to a page along with a primary route. As an example, we can have a side-menu that lives within the primary route with its own router-outlet : that's an auxiliary route.
to navigate to an other page you use this syntax: this. router. navigate(['/']); The example above would to to the home page. Save this answer.
Add the AppRoutingModule link 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.module.ts in the src/app directory. Run ng generate to create the application routing module.
@Rafael Has left the correct answer as a comment.
You would just create a link tag pointing to facebook
<a href="www.facebook.com/yourpage">Facebook</a>
The routes that you are setting up are all for local paths. In other words, all of those routes are for what is displayed on www.yoursite.com/route1, and what is displayed on www.yoursite.com/route2.
But notice that they will all have yoursite.com for the domain.
If you want to create a link to a site outside of your domain, then you do not want to mess with the angular routing, but instead create a link.
So what you're really asking is how can you show www.facebook.com's page on www.yourpage.com/facebook, which is not really possible.
Without an iframe you cannot display a different website within your own site, even with a route.
If that is really what you're trying to do, then you might want to look into iframes.
Just use a regular anchor href.
<a href="http://facebook.com">Add Vehicle</a>
or for javascript:
window.location.href = 'http://facebook.com';
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