This is a migrated thread and some comments may be shown as answers.

SPA on the MVC default route

3 Answers 67 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Will
Top achievements
Rank 1
Will asked on 17 Sep 2018, 06:19 PM

Hi,

I'm doing my first SPA application and things are going relatively well. 

One annoying glitch that I've noticed is that since my app is on the default route, the router reacts to the fully qualified route as a different page and reloads it.

E.g. http://localhost:5849/#/alert is not the same as http://localhost:5849/Home/Index/#/alert even though it really is.

I can certainly understand why this is happening.

My question, before I go off and spend a couple days coming up with my own unique hack for this, is there an established method for handling this situation?

Thanks,

Will

3 Answers, 1 is accepted

Sort by
0
Ivan Danchev
Telerik team
answered on 19 Sep 2018, 02:21 PM
Hi Will,

The router tracks navigation through the fragment part of the URL. Using the default route:
router.route("/", function() {

in the scenario you described that would mean tracking changes to the highlighted part only:

http://localhost:5849/#/alert
‚Äč

and

http://localhost:5849/Home/Index/#/alert

whereas changes to the controller and action in the URL are handled by MVC.

As for preventing navigation with the Router in general, this can be done by preventing its change event conditionally, e.g.:
if (e.url == "/test") {
    e.preventDefault();
}


Regards,
Ivan Danchev
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Will
Top achievements
Rank 1
answered on 19 Sep 2018, 02:40 PM

Ivan,

Thanks for the clarification. 

In my limited understanding of the Router I thought that it was intercepting the changes to the Url before they were sent to the server and that there might be an opportunity to manipulate them.

Maybe the answer then is just not to have an SPA on the default MVC route, forcing the Url to always be the complete path.

Thanks,

Will

0
Ivan Danchev
Telerik team
answered on 21 Sep 2018, 10:27 AM
Hi Will,

Yes, with the default MVC route the controller and action can be accessed even if not explicitly specified, e.g., http://localhost:5849, so using a route that requires the controller and action to be specified is a valid approach if you don't want the page to be accessible (and reloaded) through two different Urls.

Regards,
Ivan Danchev
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
General Discussions
Asked by
Will
Top achievements
Rank 1
Answers by
Ivan Danchev
Telerik team
Will
Top achievements
Rank 1
Share this question
or