Sorry, I forgot about this report. Here's the changed file.
To reproduce the problem.
- Make sure reloading/changing URL manually from browser won't start a new session
- Open the page from browser
- Manually change the internal path from the browser to /hatter/
The internal path will stay the same on the browser, yet the handlePathChanged slot function will remove '/hatter' from 'internalPath_'.
If you use the button 'click to find hatter', the '/hatter' would be properly removed from both, server and client.
#include <Wt/WApplication>
#include <Wt/WContainerWidget>
#include <Wt/WPushButton>
#include <Wt/WText>
using namespace Wt;
class MyApp : public WApplication
{
public:
MyApp(const WEnvironment& env)
: WApplication(env)
{
WPushButton* button = new WPushButton( "click to see alice", root() );
button->clicked().connect( this, &MyApp::changePath );
WPushButton* button2 = new WPushButton( "click to find hatter", root() );
button2->clicked().connect( this, &MyApp::changeToWrongPage );
internalPathChanged().connect( this, &MyApp::handlePathChange );
std::cout << "init: ";
handlePathChange(internalPath());
}
void changePath() { setInternalPath( "/alice/", true ); }
void changeToWrongPage() { setInternalPath( "/hatter/", true ); }
void handlePathChange( std::string path )
{
std::cout << "handlePathChange " << path << std::endl;
//Remove /hatter from the internal path IF the internal path has /hatter in it
if(path.find("/hatter") != std::string::npos)
{
setInternalPath(std::string(path).replace(path.find("/hatter"), 7, ""), false);
}
new WText( path, root() );
new WBreak( root() );
}
};
WApplication *createMyApplication(const WEnvironment& env)
{
return new MyApp(env);
}
int main(int argc, char **argv)
{
return WRun(argc, argv, &createMyApplication);
}