react
                                
                                 react copied to clipboard
                                
                                    react copied to clipboard
                            
                            
                            
                        UISref links work incorrectly with <base> and hashLocationPlugin
For <base href="/"> tag and this router setup that is used on /foo/ page:
const rootState = { name: 'root',
	url: '/',
	component: Root
};
const barState = {
	name: 'bar',
	url: '/bar',
	component: Bar
};
<UIRouter plugins={[hashLocationPlugin]} states={[rootState, barState]}>
	<div>
		<UISref to="bar"><a>bar</a></UISref>
		<UIView/>
	</div>
</UIRouter>
bar link works properly on click (goes to bar state and results in http://localhost:3000/foo/#/bar location) but the link itself is #/bar and works like http://localhost:3000/#/bar when opened in new window (because of how anchors work with <base>).
Currently UISref uses StateService href to generate a link. Since StateService is unaware of <base>, it's understandable why it generates an anchor that doesn't work as expected. Also produces a wrong link when using absolute:
stateService.href('bar', {}), // '#/bar'
stateService.href('bar', {}, { absolute: true }), // 'http://localhost:3000/#/bar'
I'm not sure how to reproduce this, as I don't understand if you are serving the app under localhost:3000/foo. From the http://localhost:3000/foo/#/bar url it looks like it.
UI-Router is handling the routing in the only after the # portion since you are using the hashLocationPlugin.
Could you set up a Codesandbox to reproduce the error?
Yes, the application is served from localhost:3000/foo/. UISref link is http://localhost:3000/#/barif
It seems that Codesandbox will have problems serving anything but /index.html
Here is a repo, https://github.com/bisubus/react-uirouter-demo
I need to experiment a bit and see what's wrong.
Out of curiosity: since you serving from /foo, why isn't base <base href="/foo">?
This is expected behaviour for anchors because they respect 
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. This does not mean that the issue is invalid. Valid issues may be reopened. Thank you for your contributions.
AFAIK, the issue is applicable to latest Router version. Does the demo needs to be updated to it?
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
This does not mean that the issue is invalid. Valid issues may be reopened.
Thank you for your contributions!
The issue is still relevant, bot.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
This does not mean that the issue is invalid. Valid issues may be reopened.
Thank you for your contributions!
The issue is still relevant, bot.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
This does not mean that the issue is invalid. Valid issues may be reopened.
Thank you for your contributions!
The issue is still relevant, bot.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
This does not mean that the issue is invalid. Valid issues may be reopened.
Thank you for your contributions!
The issue is still relevant, bot.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
This does not mean that the issue is invalid. Valid issues may be reopened.
Thank you for your contributions!
This issue has been automatically closed.