Set node.js to serve index.html for unmatched url

Recently I changed my Ionic app to not include ‘#’ in URLs, which is working fine.

$locationProvider.html5mode(true)

Now, the issue is requests to paths like localhost:8100/home/index fail as node doesnt recognize this path. How can I configure node server to serve index.html so that angular can take care of routing from there onwards. If this is not the correct approach, let me know.

with express I do this in my routes:

app.route('/*')
.get(function(req, res) {
  res.render('index.html')
});

@yurinondual Where should I include this? In hooks folder? Which subfolder is suitable for this?

This is for your routes defenition. After you define all your node API routes define one last route for all other urls i.e. “/*” to render index.html (which will have your angular app)

Do I include this as another route in $stateProvider in angular?

This is for your node server routing NOT angular routing.

Okay, but I am not sure how to edit node server configurations in ionic. Do i need to create separate project to do this?

Ah sorry! you are talking about ionic serve? I was thinking that you built your own node server… sorry

Do you have any solution?

Sorry I don’t! But why do you need a hasbang url? since nobody will ever see your urls on mobile app anyway

Actually I need the same app to be available on desktop as well like a normal website.

Atleast the read-only parts (static links)