I'm working on rebuilding an old website from a PHP-based MVC structure
platform to Angular. One of the areas where I'm currently running into a
problem with is what seems like some basic routing. I've got some paged
which are largely static HTML. It seems like overkill to create a component
for each one, so I created one component DefaultComponent (the main bulk of
the HTML is what I'm displaying as the default when the user hits the url
root of the site). In the route module, I created the following route:
{ path: 'site/:view', component: DefaultComponent }
I'm creating the links using routerLink and look like /site/FAQ,
/site/about, and /site/disclaimer, and are listed in my navigation are just
fine.
The html file then has the HTML content for all four (FAQ, about,
disclaimer, and default) outputs and I use ngIf to control which one is
visible.
In the ngOnInit routine, I extract the view parameter and use a switch to
set a flag that then controls which view should be shown. It works the
first time I click one of the links (say the FAQ link). On subsequent
clicks though, I see the URL change but the content never changes.
I feel like I'm missing something simple and basic here. I thought about
just creating components for each one, creating static routes for each one
and calling it a night, but that feels like cheating, and it seems like
this should work. I think what I'm missing is something in the lifecycle
events, as the ngOnInit happens when the controller initializes, which
happens once... which I get. So what do I need to be looking for when the
parameter on the route changes? Like I said, I can see the URL change, but
the page doesn't refresh. If I was getting data from the server through a
service, I think the example from the Tour of Heroes tutorial would help,
but I'm not doing that at this point, it's just static HTML that I'm trying
to serve up, so using a service with an observable doesn't make sense - or
am I missing something about it?
Thanks in advance.
--
You received this message because you are subscribed to the Google Groups
"Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.