How does Angular and Express routing work together in a mean.js app?

后端 未结 3 1240
一向
一向 2021-02-08 03:45

I\'m struggling about Angular and Express Routing (by the way, i\'m somehow new to Express), i\'ve been handling routes with Angular — with ui-router — but now that i\'m startin

3条回答
  •  长情又很酷
    2021-02-08 04:11

    Just two cents here. Other expert should correct me and explain further :

    Routing at frontend usually means routing management in url after #. This is because anything after # is ignored by browser. So this is utilized by angular to make on the fly ajax calls and fetch resources depending on route path after #.

    What express handles is url before #. This is used to make actual request from browser to server.

    How are they different : answered

    If i switch to Express routing will i still have a SPA :

    You can always have SPA if you manage urls manually at front end side while making ajax calls to populate your single page. managing urls at front end should be with intention of readability.

    Can i use both at same time? How? :

    Everyone uses both. A SPA also uses both. Usually authentication based thing is handled by express routing while authorization and other routing based interaction like requesting for resources and others, front end routing is used. Even if you use front end routing, for ajax request behind the scene, you are still relying on express's routing.

    Is it good practice? Does it has any benefit? :

    Using express's routing for authentication and providing resources AND using angular routing for front end to keep SPA in action is always a good practice.

    When should i use only one of them? : answered

    How will i handle route parameters? :

    There are parameters handling both for front end side using route params ( if using ng-route) and at the back end using slug, bodyparser and others. You need to spare some time learning those.

提交回复
热议问题